我正在尝试从python连接到Mysql服务器。 并且出现以下错误:
Traceback (most recent call last):
File "./db_connection.py", line 2, in <module>
Con = MySQLdb.Connect(host="127.0.0.1",port= 3360, user="username",
passwd="password", db="entries")
File "/usr/lib64/python2.7/site-packages/MySQLdb/__init__.py", line
85, in Connect
return Connection(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py",
line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL
server on '127.0.0.1' (111)")
我检查了,我的端口是0:
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 0 |
+---------------+-------+
1 row in set (0.01 sec)
并且skip_networking = ON:
mysql> SHOW VARIABLES LIKE 'skip_networking';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| skip_networking | ON |
+-----------------+-------+
1 row in set (0.00 sec)
文件my.cnf如下所示:
[mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
我试图将skip-networking = Off并设置为port = 3360,然后重新启动mysql服务,但它不起作用-skip_networking仍然打开。 关于如何将MySQL DB与python连接的任何建议?
谢谢!
答案 0 :(得分:0)
如果使用--skip-grant-tables
选项启动服务器以禁用身份验证检查,则服务器将启用--skip-networking
来阻止远程连接。
您应该评论--skip-grant-tables
。