HOME/Articles/

mysql example mysqlconntest (snippet)

Article Outline

Python mysql example 'mysqlconntest'

Modules used in program:

  • import mysql.connector

python mysqlconntest

Python mysql example: mysqlconntest

import mysql.connector

database = mysql.connector.connect( 
  host="localhost", #Or ip address of the database
  user="dbusername", #Username of the database
  passwd="dbpassword", #Password
  database="dbname"
)

cursor = database.cursor() #I use this variable to execute queries