Skip to content

Instantly share code, notes, and snippets.

@madan712
Last active June 23, 2019 09:35
Show Gist options
  • Save madan712/9e0423bfd9c168f34b75a656c4696425 to your computer and use it in GitHub Desktop.
Save madan712/9e0423bfd9c168f34b75a656c4696425 to your computer and use it in GitHub Desktop.
Python - Connect mysql
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