docneogi
docneogi

Reputation: 55

Error in importing MySQL connector in Python 3.5

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.

Upvotes: 1

Views: 15894

Answers (4)

lahiri kolli
lahiri kolli

Reputation: 11

As we need to be connecting MySQl with Python, the Python command assumes that the connector is enabled. So we need to follow the steps below:

  1. open MySQL Installer;
  2. go to "Custom settings";
  3. go to "Connectors";
  4. choose the connector\Python and version based on the one you are using;
  5. add it;
  6. use import mysql.connector.

It should run, in my case it did!

Upvotes: 1

drem
drem

Reputation: 21

For me (OS X 10.11.4, Python 3.5.1), the mysql-connector-package installed itself (by default) into Python 2.7 that was also on my system. I copied the mysql package directory from: /Library/Python/2.7/site-packages/mysql to /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mysql. Everything works. According to http://dev.mysql.com/doc/connector-python/en/connector-python-versions.html the connector package supports Python 3.3+.

Your specific installation path for the module may be different, but you can easily check this from the REPL using the sys.path: https://leemendelowitz.github.io/blog/how-does-python-find-packages.html

Upvotes: 2

Suresh2692
Suresh2692

Reputation: 3918

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()

Upvotes: 2

Dharani Dharan
Dharani Dharan

Reputation: 644

From Can't run MySql Utilities:

MYSQL Utilities assumes that the MySQL Connector for Python has been installed. If you install it (http://dev.mysql.com/downloads/connector/python/), MySQL Utilities should run OK.

I think this link may help you to solve your problem.

Upvotes: 0

Related Questions