——表更表
update user set host = ’%’ where user = ’root’;
grant all privileges on . to root@’%’ identified by “password”;
⚠️⚠️BUT
遠程連接mysql仍能出現Can’t connect to MySQL server on (111 “Connection refused”)
或者
telnet xxxxxxx 3306
Trying xxxxxxx…
telnet: connect to address xxxxx: Connection refused
telnet: Unable to connect to remote host
這裡有坑。。。。。。
我一直在看防火牆,安全組等這些,都開放了3306,但是一直telnet不通,尷尬啊。
解決方案
先查mysql有沒有對應3306端口(無語,我就沒有查)
登陸mysql以後:使用命令show global variables like ‘port’;查看端口號
mysql> show global variables like ‘port’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| port | 3306 |
+—————+——-+
1 row in set (0.00 sec)
如果是的話,然後再回去看是否開放3306端口和安全組等,推薦博文:
https://blog.csdn.net/Ivy___/article/details/54708972
如果不是,修改/etc/my.cnf
[mysqld]
port=3306
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
二:密碼加密校驗
Authentication plugin ‘caching_sha2_password’ cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2):
表明:這種密碼加密方式【caching_sha2_password】,客戶端不支持
解決方案:
ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘newpassword’;
閱讀更多 nicky猿 的文章