故障分析 | 业务连不上数据库了?小心你的 skip-networking 配置


外向笑小鸭子
外向笑小鸭子 2024-01-02 10:25:00 49214
分类专栏: 资讯

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 变量默认也会开启,此时禁用任何远程连接。

3结论

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

 

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=34086
赞同 0
评论 0 条
外向笑小鸭子L0
粉丝 0 发表 622 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2941
【软件正版化】软件正版化工作要点  2860
统信UOS试玩黑神话:悟空  2819
信刻光盘安全隔离与信息交换系统  2712
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1246
grub引导程序无法找到指定设备和分区  1213
华为全联接大会2024丨软通动力分论坛精彩议程抢先看!  163
点击报名 | 京东2025校招进校行程预告  162
2024海洋能源产业融合发展论坛暨博览会同期活动-海洋能源与数字化智能化论坛成功举办  160
华为纯血鸿蒙正式版9月底见!但Mate 70的内情还得接着挖...  157
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
信创开放社区邀请他人注册的具体步骤如下 15
如何玩转信创开放社区—从小白进阶到专家 15
方德桌面操作系统 14
我有15积分有什么用? 13
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!