1. 程式人生 > >mysql遠端連線的坑

mysql遠端連線的坑

一:授權

變更表或者授權
——表更表
update user set host = ’%’ where user = ’root’;

——-授權
grant all privileges on . to [email protected]’%’ 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)

如果不是,修改/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’;