Reputation: 121
I am learning a new library mysql in python. I have tried executing the below command,
import mysql.connector
mydb= mysql.connector.connect(
host= 'localhost',
user= 'root',
passwd= 'skviknesh'
)
print(mydb)
and got the below error!
Traceback (most recent call last):
File "<ipython-input-1-f9b9bc67dd68>", line 3, in <module>
mydb= mysql.connector.connect(
AttributeError: module 'mysql.connector' has no attribute 'connect'
I looked into similar other Stack overflow questions... Didn't get a solution. I tried renaming my file too, that didn't help. Please help on the same!!!
Upvotes: 4
Views: 13592
Reputation: 75
I was also facing the same issue while i am trying to connect to mysql from python, i have corrected below issue, you may have one of the issue below
Upvotes: 0
Reputation: 727
This generally happens when you install the wrong package.
Probably during installation, you have used the following pip command:
pip install mysql-connector
But you are required to install the package:
pip install mysql-connector-python
Like this:
C:\Users\tuhin Mitra>pip install mysql-connector-python
Requirement already satisfied: mysql-connector-python in c:\users\tuhin mitra\appdata\local\programs\python\python37-32\lib\site-packages (8.0.19)
Requirement already satisfied: protobuf==3.6.1 in c:\users\tuhin mitra\appdata\local\programs\python\python37-32\lib\site-packages (from mysql-connector-python) (3.6.1)
Requirement already satisfied: dnspython==1.16.0 in c:\users\tuhin mitra\appdata\local\programs\python\python37-32\lib\site-packages (from mysql-connector-python) (1.16.0)
Requirement already satisfied: setuptools in c:\users\tuhin mitra\appdata\local\programs\python\python37-32\lib\site-packages (from protobuf==3.6.1->mysql-connector-python) (45.1.0)
Requirement already satisfied: six>=1.9 in c:\users\tuhin mitra\appdata\roaming\python\python37\site-packages (from protobuf==3.6.1->mysql-connector-python) (1.12.0)
Upvotes: 1
Reputation: 111
When I had the same problem. I had to just uninstall the package with pip uninstall mysql-connector-python
and reinstall it with pip install mysql-connector-python
and it worked :D
Upvotes: 11