Created
August 16, 2019 15:27
-
-
Save yogesh-aggarwal/3ed8b0465eeab5a29670ed56d76d2b58 to your computer and use it in GitHub Desktop.
Basic MySQL-Python connector code to connect database.
This file contains 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 | |
db_connection = mysql.connector.connect( | |
host= "localhost", | |
user= "root", | |
passwd= "root" | |
) | |
# creating database_cursor to perform SQL operation | |
db_cursor = db_connection.cursor() | |
# executing cursor with execute method and pass SQL query | |
# db_cursor.execute("CREATE DATABASE my_firs") | |
# get list of all databases | |
result = db_cursor.execute("SHOW DATABASES;") | |
print(result) | |
#print all databases | |
# print(db_cursor) | |
# for db in db_cursor: | |
# print(db) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment