python mysql show databases 1

python mysql show databases

import mysql.connector
conn = mysql.connector.connect (user='user', password='password',
cursor = conn.cursor()
databases = ("show databases")
for (databases) in cursor:
     print databases[0]

Here is what the above code is Doing:
1. Connect to the database server
2. Create a cursor object
3. Create a string variable with the SQL query
4. Execute the query
5. Loop through the results and print them

Similar Posts