Checking MySQL database connection with mysql-connector-python

October 10, 2015 by Zemian Deng Comment

Tags: python mysql

First install the MySQL package

bash>pip install --allow-all-external mysql-connector-python

Now you may test the database connection with this Python code

from mysql.connector import connect

conn = connect(user='dev', password='dev123', database='mysql')
cur = conn.cursor()
cur.execute('select 1+1')
for row in cur: