20、查询MySQL网络配置

1. 检查MySQL服务状态

// 检查MySQL服务是否运行
sudo systemctl status mysql
// 或者
sudo systemctl status mysqld

// 如果服务未运行,启动服务
sudo systemctl start mysql
sudo systemctl enable mysql  // 设置开机自启

// 重启服务(如果正在运行)
sudo systemctl restart mysql

检查MySQL网络配置

登录MySQL检查绑定地址:

-- 查看MySQL绑定地址
SHOW VARIABLES LIKE 'bind_address';
SHOW VARIABLES LIKE 'port';
SHOW VARIABLES LIKE 'skip_networking';

-- 如果bind_address是127.0.0.1,只能本地连接
-- 需要修改为0.0.0.0或服务器IP
mysql> SHOW VARIABLES LIKE 'bind_address';
+---------------+-----------+
| Variable_name | Value     |
+---------------+-----------+
| bind_address  | 127.0.0.1 |
+---------------+-----------+
1 row in set (0.01 sec)

修改MySQL配置:

// 编辑MySQL配置文件
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
//
sudo vim /etc/my.cnf

// 在 [mysqld] 部分添加或修改:
[mysqld]
bind-address = 0.0.0.0          // 允许所有IP连接
# bind-address = 192.168.1.100  // 或指定服务器IP
port = 3306                     // 确保端口正确
skip-networking = OFF           // 确保网络连接开启

重启MySQL服务:

sudo systemctl restart mysql

 

posted @ 2025-11-18 11:14  chao_xiong  阅读(8)  评论(0)    收藏  举报