I'm trying to run the following code on WSL - Windows Version 1809 and Ubuntu 18.04:
# Connect to a database
mydb = MySQLdb.connect(
host='localhost',
user='root',
passwd='',
db='mydb'
)
But then I get the error
Traceback (most recent call last):
File "/home/queenmypawn/.local/lib/python3.6/site-packages/pymysql/connections.py", line 583, in connect
**kwargs)
File "/usr/lib/python3.6/socket.py", line 724, in create_connection
raise err
File "/usr/lib/python3.6/socket.py", line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
It also throws another exception:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "csvtodb.py", line 16, in <module>
db='mydb'
File "/home/queenmypawn/.local/lib/python3.6/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/home/queenmypawn/.local/lib/python3.6/site-packages/pymysql/connections.py", line 325, in __init__
self.connect()
File "/home/queenmypawn/.local/lib/python3.6/site-packages/pymysql/connections.py", line 630, in connect
raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")
What seems to be the problem with the line db='mydb'
?