Connecting to a MySQL Database Server : MySQL : Database PYTHON TUTORIALS


PYTHON TUTORIALS » Database » MySQL »

 

Connecting to a MySQL Database Server


import MySQLdb

myDB = MySQLdb.connect(host="127.0.0.1", port=3306)
cHandler = myDB.cursor()

cHandler.execute("SHOW DATABASES")
results = cHandler.fetchall()
for item in results:
    print item[0]

cHandler.execute("SELECT DATABASE()")
results = cHandler.fetchall()
for item in results:
    print item[0]

cHandler.execute("USE schedule")

cHandler.execute("SELECT DATABASE()")
results = cHandler.fetchall()
for item in results:
    print item[0]
myDB.close()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Database
» MySQL