Error in importing MySQL connector in Python 3.5

docneogi picture docneogi · Nov 18, 2015 · Viewed 14.5k times · Source

I am getting ImportError: No module named 'mysql' while I do the following...

>>> import mysql.connector

MySQL is installed and am on Python 3.5. I can't figure out. The above command is running fine in Python 2.7.

Answer

Suresh2692 picture Suresh2692 · Mar 14, 2016

Unfortunately there is no mysql-connector available for python3.5.

So, you can use pymysql module which is a replacement for mysql-connector package

pip install pymysql

import pymysql
Connection = pymysql.connect(host='hostname', user='username', password='password', 
             db='database',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor )
ExecuteQuery(Connection)
Connection.close()