1 year ago
#330180
Snow
python3.9 pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 61] Connection refused)")
pls tell me how to deal with the problem
import pymysql
conn = pymysql.connect(host='localhost',port=3306,user ='root',password ='123456',database ='account',charset ='utf8')
cursor = conn.cursor()
cursor.execute('show databases;')
for x in cursor:
print (x)
cursor.close()
conn.close()
[run result] File "/Users/user/Library/Python/3.9/lib/python/site-packages/pymysql/connections.py", line 353, in init self.connect() File "/Users/user/Library/Python/3.9/lib/python/site-packages/pymysql/connections.py", line 664, in connect raise exc pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 61] Connection refused)")
mysql version is mysql-8.0.28-macos11-x86_64
localhost change to 127.0.0.1 , is also not ok~~ but the same params is ok in navicat expect for the config 'use socket file : /tmp/mysql.sock'~~ enter image description here in navicat , if i do not check the socket option ,i receive the same problem as python code above
expect to link mysql succesfully , thx
mysql
python-3.x
pymysql
0 Answers
Your Answer