Created
September 17, 2018 08:10
-
-
Save jsrpy/1bef2fae4451b56af9c45f569072ea96 to your computer and use it in GitHub Desktop.
Connect with mysql database using mysql.connector and 'SHOW DATABASES'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mysql.connector | |
conn = mysql.connector.connect(host="localhost", user="root", passwd="root", | |
#database='', | |
auth_plugin='mysql_native_password') # for MySQL 8.0 above | |
print(conn) | |
cursor = conn.cursor() | |
databases = ('show databases') | |
cursor.execute(databases) | |
print(cursor) | |
for databases in cursor: | |
print(databases) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment