无法使用pymysql连接到mysql

时间:2018-06-22 06:55:07

标签: python mysql python-2.7 mysql-python pymysql

我正在尝试使用以下在仓库中共享的example脚本从pymysql连接到mysql,但是它始终失败并显示以下消息。

  File "/Users/svenkatesh/Library/Python/2.7/lib/python/site-packages/pymysql/connections.py", line 818, in _connect
    2003, "Can't connect to MySQL server on %r (%s)" % (self.host, e))
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (255)")

这是mysql用户配置,我尝试了 root rv

mysql> select user, host, plugin from user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | mysql_native_password |
| mysql.session    | localhost | mysql_native_password |
| mysql.sys        | localhost | mysql_native_password |
| root             | localhost | caching_sha2_password |
| rv               | localhost | mysql_native_password |

mysql服务似乎也可以在所需的端口上正常运行。

C02WK0DQHV2J:Downloads svenkatesh$ sudo lsof -nPi -sTCP:LISTEN | grep sql
Password:
mysqld    15390         _mysql   19u  IPv6 0xf35d852c37f052c1      0t0  TCP *:3306 (LISTEN)
mysqld    15390         _mysql   22u  IPv6 0xf35d852c3792ce41      0t0  TCP *:33060 (LISTEN)

C02WK0DQHV2J:Downloads svenkatesh$ sudo netstat -an | grep -i sql
f35d852c413e4b61 stream      0      0 f35d852c463e3ca9                0                0                0 /tmp/mysqlx.sock
f35d852c413e65f1 stream      0      0 f35d852c44094009                0                0                0 /tmp/mysql.sock

0 个答案:

没有答案