MySQL 8.0 不能被遠程鏈接的解決辦法及修改密碼、建立用戶、授予全部權

MySQL能在本地能鏈接上,不能被遠程鏈接的解決辦法:mysql

進入數據庫,命令
 # mysql -u root -p
 # 輸入mysql登陸密碼
 
 一下命令均在mysql環境下執行。
 
 use mysql;
 SELECT user, host, plugin from mysql.user;
 //查看用於遠程訪問的mysql用戶host的權限,%表示容許全部機器訪問。若host爲127.0.0.1/localhost,那麼這個用戶就只能本機訪問,則須要將host改成%sql

plugin:數據庫

mysql新版本(8.0以上)將root用戶使用的加密方式plugin更新成caching_sha2_passwordide

5.x是mysql_native_password
   
update user set host='%' where user='root';ui

//若輸出ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'this

//執行加密

flush privileges;spa

//再查看權限rem

SELECT user, host from mysql.user;
   
OK.能夠遠程登陸啦!it

---------------------------------------------------------------------------------------------------------------------------------

MySQL修改密碼、建立用戶、授予全部權

修改密碼:

alter user 'root'@'localhost' identified by '123456';

建立用戶與受權:

create user 'lgl'@'%' identified by '123456';

grant all privileges on *.* to lgl@'%';

---------------------------------------------------------------------------------------------------------------------------------

MySQL8.0的一些疑難雜症

出現

Mysql 8.0.11 出現1251- Client does not support authentication protocol 錯誤

OR

this authentication plugin is not supported

爲了使lgl用戶能經過遠程登陸到新版8.0的MySQL數據庫

alter user 'lgl'@'%' identified with mysql_native_password by '123456';

---------------------------------------------------------------------------------------------------------------------------------

設置簡單密碼過程

出現

mysql> alter user 'root'@'localhost' identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0;
ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
mysql> set global validate_password_length=1;
ERROR 1193 (HY000): Unknown system variable 'validate_password_length'

解決方法
MySQL 5.x
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

MySQL 8.0
mysql> set global validate_password.policy=0;
mysql>  set global validate_password.length=1;

mysql> alter user 'root'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.05 sec)

相關文章
相關標籤/搜索