找到并编辑配置文件
Ubuntu/Debian 系统路径通常是:/etc/mysql/mysql.conf.d/mysqld.cnf
CentOS/RHEL 系统路径通常是:/etc/my.cnf
使用 vim 编辑:
修改 bind-address 参数
找到 [mysqld] 部分下的 bind-address = 127.0.0.1,将其改为 0.0.0.0:
ini
mysqld
允许监听所有网络接口
bind-address = 0.0.0.0
注意:如果该行前有#,记得删掉。改为0.0.0.0表示允许从任何网络接口访问,如果想更安全,可以指定你服务器的具体内网IP。
重启MySQL服务
sudo systemctl restart mysqld