MySQL的skip-networking配置影响

MySQL的参数很多,这就要求了解清楚参数的含义,再进行相应调整,技术社群的这篇文章《故障分析 | 业务连不上数据库了?小心你的 skip-networking 配置》给我们介绍了skip-networking参数改动的影响。

1背景

某客户的测试同事本地部署 MySQL 8.0 数据库,配置文件增加了部分变量重启数据库之后发现数据库远程连接失败。

2排查

1 查看数据库进程状态

[root@hao-3 ~]# ps -ef|grep mysqld |grep 8888
actiont+ 25825     1  0 02:10 ?        00:00:01 /opt/mysql/base/8.0.28/bin/mysqld --defaults-file=/opt/mysql/etc/8888/my.cnf --daemonize --pid-file=/opt/mysql/data/8888/mysqld.pid --user=actiontech-mysql --socket=/opt/mysql/data/8888/mysqld.sock --port=8888

2 查看服务 TCP 连接情况

使用 netstat 命令查看数据库服务的 TCP 连接情况,输出结果为空。

[root@hao-3 ~]# ps -ef|grep mysqld|grep 8888
actiont+ 25825     1  0 02:10 ?        00:00:05 /opt/mysql/base/8.0.28/bin/mysqld --defaults-file=/opt/mysql/etc/8888/my.cnf --daemonize --pid-file=/opt/mysql/data/8888/mysqld.pid --user=actiontech-mysql --socket=/opt/mysql/data/8888/mysqld.sock --port=8888
[root@hao-3 ~]# netstat  -lantup |grep 25825       //查看进程
[root@hao-3 ~]#
[root@hao-3 ~]# netstat  -lantup |grep 8888        //查看端口
[root@hao-3 ~]#

3 查看数据库端口

查看数据库端口,结果为 0!

[root@hao-3 ~]# /opt/mysql/base/8.0.28/bin/mysql -uroot -p1 -S /opt/mysql/data/8888/mysqld.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.28 MySQL Community Server - GPL
 
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 0     |
+---------------+-------+
1 row in set (0.00 sec)

4 查看配置文件

发现客户配置了 skip_networking 变量。该配置会导致数据库无法通过 TCP/IP 进行连接。

mysql> show variables like '%networking%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| skip_networking | ON    |
+-----------------+-------+
1 row in set (0.00 sec)
 
 
[root@hao-3 ~]# grep skip /opt/mysql/etc/8888/my.cnf
skip_external_locking = 1
skip_name_resolve = 1
skip_replica_start = 1
skip_networking=on

5 官方文档解释

skip_networking 控制 MySQL 服务是否允许 TCP/IP 连接,默认是关闭。如果开启这个变量,MySQL 服务只允许本地连接,不允许任何 TCP/IP 连接。

需要注意的是当配置了 --skip-grant-tables 变量之后,skip_networking 变量默认也会开启,此时禁用任何远程连接。

4e1a54b7e2322040e363f0f470869fd7.png
官方手册说明

3因此

skip_networking 变量需要根据业务情况来进行配置,对于只允许本地访问的 MySQL 数据库系统来说,强烈建议配置该变量;对于大部分需要远程访问的数据库是不需要进行配置的,保持默认关闭就可以。这个变量不能动态修改,需要修改配置文件,然后重启数据库服务。

如果您认为这篇文章有些帮助,还请不吝点下文章末尾的"点赞"和"在看",或者直接转发pyq,

a3c3198584b469189547d8303692ca30.png

近期更新的文章:

应用运维值班体系的思考

我的老朋友,天堂之上,愿你安好

MySQL分区和分表的基础介绍

数据库的ACID属性是什么?

企业数据库安全管理规范指导

近期的热文:

推荐一篇Oracle RAC Cache Fusion的经典论文

"红警"游戏开源代码带给我们的震撼

文章分类和索引:

公众号1400篇文章分类和索引

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值