简体   繁体   English

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

[英]Mysql - How to set skip_networking to off?

I'm Trying to connect to Mysql server from python.我正在尝试从 python 连接到 Mysql 服务器。 and i'm getting the following error:我收到以下错误:

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)")

I checked and my port is 0 :我查了一下,我的端口是 0 :

mysql> show variables like 'port';

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 0     |
+---------------+-------+
1 row in set (0.01 sec)

and skip_networking=ON:和skip_networking=ON:

mysql> SHOW VARIABLES LIKE 'skip_networking';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| skip_networking | ON    |
+-----------------+-------+
1 row in set (0.00 sec)

file my.cnf looks like that:文件 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

I tried to put skip-networking = Off and port=3360 and then restart mysql service and it didn't work- skip_networking is still on.我尝试将 skip-networking = Off 和 port=3360 设置为关闭,然后重新启动 mysql 服务,但没有成功——skip_networking 仍在运行。 Any suggestions on how to connect MySQL DB with python?关于如何将 MySQL DB 与 python 连接的任何建议?

Thanks!谢谢!

If the server is started with the --skip-grant-tables option to disable authentication checks, the server enables --skip-networking to prevent remote connections. 如果使用--skip-grant-tables选项启动服务器以禁用身份验证检查,则服务器将启用--skip-networking以阻止远程连接。

Yo should comment the --skip-grant-tables . 您应该评论--skip-grant-tables

First Thing you need to do is stop your MYSQL server.您需要做的第一件事是停止您的 MYSQL 服务器。

if you are using Mac,如果您使用的是 Mac,

sudo /usr/local/mysql/support-files/mysql.server stop

Then you have to put this line.然后你必须把这条线。 the value should set to 0.该值应设置为 0。

sudo mysqld_safe --skip_networking=0

then you can close the terminal window, and re-open it and connect to the mysql again.然后您可以关闭终端窗口,然后重新打开它并再次连接到 mysql。 your port will be reset and, skip_networking should be reset to OFF.您的端口将被重置,skip_networking 应该被重置为 OFF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM