Reputation: 3021
I am using MySQLdb
in python3.5.2 to connect to mysql. I have done this in many machine and have never faced issues. In a new machine, I have installed
MySQL-5.7.24-0ubuntu0.16.04.1 (Ubuntu) version. And I am using the following code to connect:
import MySQLdb
conn=MySQLdb.connect(host="localhost",user="root", passwd="Abcabc", db="testdb",port=3306)
I am getting the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/.virtualenvs/tfod_api/lib/python3.5/site-packages/MySQLdb/__init__.py", line 80, in Connect
from MySQLdb.connections import Connection
File "/home/ubuntu/.virtualenvs/tfod_api/lib/python3.5/site-packages/MySQLdb/connections.py", line 36
raise errorclass, errorvalue
^
SyntaxError: invalid syntax
I couldn't figure out any syntax error here and the same code is working in many other machines. Shall I uninstall MySQL and try again. This requires me to create multiple tables again. What should I do?
Upvotes: 0
Views: 1118
Reputation: 541
You can use pymysql
as MySQLdb
doesn't have python3 support
check following links
https://raspberrypi.stackexchange.com/questions/78215/how-to-connect-mysqldb-in-python-3
or
How can I connect to MySQL in Python 3 on Windows?
Upvotes: 2