MySQL如何開啟用戶遠(yuǎn)程登錄權(quán)限
目錄
- MySQL開啟用戶遠(yuǎn)程登錄權(quán)限
- 開放MySQL的遠(yuǎn)程訪問權(quán)限
- 總結(jié)
MySQL開啟用戶遠(yuǎn)程登錄權(quán)限
當(dāng)在Docker中創(chuàng)建一個(gè)Mysql的容器后,需要使用工具如:navicate來連接容器內(nèi)的MySQL服務(wù),但是
提示Access denied for user 'root'@ 'x.x.x.x' (using password: YES) 錯(cuò)誤,用命令進(jìn)入容器確認(rèn)密碼沒有問題,那么就可能是沒有開發(fā)遠(yuǎn)程權(quán)限。
第一步:選中mysql數(shù)據(jù)庫
use mysql;
第二步:修改庫中user表中,user用戶的host=%(任意連接)
update user set host="%" where user ="root";
第三步:重新加載權(quán)限表
flush privileges;
第四步:給root用戶賦予遠(yuǎn)程連接權(quán)限
grant all privileges on *.* to "root"@"%" with grant option; # 賦予權(quán)限并修改密碼 alter user "root"@"%" identified with mysql_native_password by "123456";
開放MySQL的遠(yuǎn)程訪問權(quán)限
1.使用 mysql -u root -p 連接到本地MySQL服務(wù)
2.登錄后使用 use mysql;
3.使用 grant all privileges on . to ‘root’@‘%’ identified by ‘123456’ with grant option; 賦予遠(yuǎn)程登錄用戶權(quán)限(使用root賬號(hào)和密碼123456,從任何主機(jī)連接到mysql服務(wù)器),刷新權(quán)限 FLUSH PRIVILEGES;
4.使用 select user,host from user 查看系統(tǒng)用戶
5.使用 vim /etc/mysql/mysql.conf.d/mysqld.cnf 修改bind-address的訪問網(wǎng)址,將 bind-address=127.0.0.1 改成 bind-address=0.0.0.0
6.開放端口 3306(這是MySQL的默認(rèn)端口)
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持。
