① 设置MySQL中root用户的权限:
mysql
[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端口
shell
[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。