This is a fork of MySQL offical maintained mysql-connector-python. Aim to get started easily for beginners.
From PyPI (recommend)
pip install mysql-connectorFrom source code
python setup.py installDocumentation for all Connector/Python versions can be found online here:
dev.mysql.com/doc/connector-python/en/
import mysql.connector from mysql.connector import errorcode config = { 'user': 'root', 'password': '', 'host': '127.0.0.1', 'database': 'test' } cnx = cur = None try: cnx = mysql.connector.connect(**config) except mysql.connector.Error as err: if err.errno == errorcode.ER_ACCESS_DENIED_ERROR: print('Something is wrong with your user name or password') elif err.errno == errorcode.ER_BAD_DB_ERROR: print("Database does not exist") else: print(err) else: cur = cnx.cursor() cur.execute('show databases;') for row in cur.fetchall(): print(row) finally: if cur: cur.close() if cnx: cnx.close()