Last active
June 23, 2019 09:35
-
-
Save madan712/9e0423bfd9c168f34b75a656c4696425 to your computer and use it in GitHub Desktop.
Python - Connect mysql
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 | |
# The connect() constructor creates a connection to the MySQL server and returns a MySQLConnection object. | |
cnx = mysql.connector.connect( | |
host="localhost", | |
database="schema", | |
user="root", | |
password="password" | |
) | |
# Test the connection | |
print(cnx) | |
cursor = cnx.cursor() | |
cursor.execute("select * from TABLE_NAME") | |
for x in cursor: | |
print(x) | |
cnx.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment