Cant import mysql.connector in python

  mariadb, mysql, mysql-connector, python

I’ve installed several types of this mysql-connector such as mysql-connector and mysql-connector-python and mysql-connector-rf.

But it keeps saying its not imported. And when im trying to install the mysql-connector-rf it comes with a big red error message.

This is the error code when im trying to run my test.py:

PS C:UsersOscar GPOneDrive - Aalborg UniversitetGPROaaugpromysqlopgaveark1> & "C:/Users/Oscar GP/AppData/Local/Programs/Python/Python38-32/python.exe" "c:/Users/Oscar GP/OneDrive - 
Aalborg Universitet/GPRO/aau/gpro/mysql/opgaveark1/opgave1/test.py"
Traceback (most recent call last):
  File "c:/Users/Oscar GP/OneDrive - Aalborg Universitet/GPRO/aau/gpro/mysql/opgaveark1/opgave1/test.py", line 1, in <module>
    import mysql.connector
ModuleNotFoundError: No module named 'mysql'
PS C:UsersOscar GPOneDrive - Aalborg UniversitetGPROaaugpromysqlopgaveark1>

and the python file:

import mysql.connector

db = mysql.connector.connect (
    host='localhost',
    user='oscar',
    pwd='password',
    database='gpro1'
)

cursor = db.cursor (dictionary = True)
cursor.execute ("CREATE TABLE IF NOT EXISTS TestTable (id INTEGER)")

for i in range (0,100):
    cursor.execute (f"INSERT INTO TestTable VALUE({i})")
db.commit ()

Source: Python Questions

LEAVE A COMMENT