Home > front end >  No module named "mysql"
No module named "mysql"

Time:07-12

I am connecting python and mysql but when I am running the program, I get the following error:

Traceback (most recent call last):
  File "C:/Users/Dell/Desktop/SAM1.py", line 6, in <module>
    import mysql.connector
ModuleNotFoundError: No module named 'mysql'

I have referred a similar question on this error whose link is as follows: ImportError: No module named 'MySQL'

This is the exact replication of what i did after seeing the answer given in the mentioned link

but somehow things are not working out for me. Here is the code

print("Enter 1 to insert train records")
print("Enter 2 to update train records")
print("Enter 3 to delete train records")
print("Enter 4 to see all the records")
a=int(input("Enter the option"))
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="0000",database="test")
tracur=mydb.cursor()
tracur.execute("CREATE TABLE IF NOT EXISTS TMS1(Train_no varchar(20) primary key,Train_name 
char(150),Departing_station char(100),Arriving_station char(100),Departing_time 
varchar(100),Arriving_time varchar(100))")






if a==1:
    mydb=mysql.connector.connect(host="localhost",user="root",passwd="0000",database="test")
    tracur=mydb.cursor()
    b=input("Enter the Train Number: ")
    c=input("Enter the Train Name: ")
    d=input("Enter the Departing Station: ")
    e=input("Enter the Arriving Station: ")
    f=input("Enter the Departing Time: ")
    g=input("Enter the Arriving Time: ")
    tracur.execute("INSERT INTO 
TMS1(Train_no,Train_name,Departing_station,Arriving_station,Departing_time,Arriving_time)VALUES(%s,%s,%s,%s,%s,%s",(b,c,d,e,f,g))
mydb.commit()
mydb.close()

It would be grate if you could help me out with this code.

CodePudding user response:

Install the necessary package using:

pip install mysql-connector-python
  • Related