-1

im trying to connect my python script to mysql, but any of the mysql python connectors does'nt work.

Here is part of my code:

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  passwd="",
  database="mydatabase"
)

and here is error:

 Traceback (most recent call last):
   File "type.py", line 1, in <module>
     import mysql.connector
   File "/root/mysql.py", line 1, in <module>
     import mysql.connector
 ImportError: No module named connector
3

2 Answers 2

0

You may not have Connector installed, I would recommend using pip list to see if it is or pip install mysql-connector-python.

This is a great resource: https://dev.mysql.com/doc/connector-python/en/connector-python-installation-binary.html

Sign up to request clarification or add additional context in comments.

Comments

0

You can first check whether mysqlconnector is installed on your device or not.
For this the simplest way is

  • to write import mysql.connector on interactive mode and hit enter;
  • if it doesn't give you error then your good.
  • If it does,
    • then go to tools > open system shells >
    • type : pip install mysql.connector > press enter.
    • This is install the connector and try it again after it is installed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.