gpt4 book ai didi

python - Mysql - 如何将skip_networking设置为关闭?

转载 作者:行者123 更新时间:2023-11-29 17:19:51 25 4
gpt4 key购买 nike

我正在尝试从 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仍然打开。关于如何使用 python 连接 MySQL DB 有什么建议吗?

谢谢!

最佳答案

如果服务器启动时使用 --skip-grant-tables 选项禁用身份验证检查,则服务器会启用 --skip-networking 以阻止远程连接。

你应该注释--skip-grant-tables

关于python - Mysql - 如何将skip_networking设置为关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51318547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com