关键错误信息
pymysql.err.OperationalError: (2003, “Can’t connect to MySQL server on ‘localhost’ ([Errno 8] nodename nor servname provided, or not known)”)
全部错误信息
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pymysql/connections.py", line 583, in connect
**kwargs)
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "sql.py", line 7, in <module>
db = pymysql.connect(host="localhost", user="root", password="123456", db="mydb", charset="utf8")
File "/usr/local/lib/python3.7/site-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/pymysql/connections.py", line 325, in __init__
self.connect()
File "/usr/local/lib/python3.7/site-packages/pymysql/connections.py", line 630, in connect
raise exc
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 8] nodename nor servname provided, or not known)")
Johnny:test_sql johnny$
解决方案
-
$
sudo vi /etc/hosts -
edit this file by adding blow :
127.0.0.1 localhost
313



被折叠的 条评论
为什么被折叠?



