① 设置MySQL中root用户的权限:
[root@nginx-dev etc]# mysql -uroot -pRoot@123
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root@123' WITH GRANT OPTION;
mysql> select host,user,authentication_string from user;
+-------------+----------------------+-------------------------------------------+
| host | user | authentication_string |
+-------------+----------------------+-------------------------------------------+
| localhost | root | *E32A671056805EBAD613F4090727279564EED370 |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| % | root | *E32A671056805EBAD613F4090727279564EED370 |
| % | myuser | *FABE5482D5AADF36D028AC443D117BE1180B9725 |
+-------------+----------------------+-------------------------------------------+
mysql> flush privileges;
mysql> quit
[root@nginx-dev etc]# service mysqld restart
第一个root用户只能从本地主机连接,而第二个root用户可以从任何主机连接。
② 检查防火墙有没有屏蔽掉3306端口
[root@nginx-dev etc]# systemctl start firewalld
[root@nginx-dev etc]# sudo firewall-cmd --permanent --zone=public --add-port=13306/tcp
Warning: ALREADY_ENABLED: 13306:tcp
success
[root@nginx-dev etc]# sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
Warning: ALREADY_ENABLED: 3306:tcp
success
[root@nginx-dev etc]# sudo firewall-cmd --zone=public --list-ports
13306/tcp 3306/tcp
[root@nginx-dev etc]# netstat -apn | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4379/mysqld
tcp 0 0 192.168.1.9:3306 192.168.1.10:65037 ESTABLISHED 4379/mysqld
tcp 0 0 192.168.1.9:3306 192.168.1.10:65041 ESTABLISHED 4379/mysqld
③ 修改配置文件/etc/my.cnf,绑定IP设置为0.0.0.0,即接收任意地址的主机的连接,端口绑定3306。文章来源:https://www.toymoban.com/news/detail-674442.html
文章来源地址https://www.toymoban.com/news/detail-674442.html
到了这里,关于解决无法远程连接MySQL服务的问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!