Mysql學習中,嘗試遠程登錄報(2059)錯誤:(從虛擬機登錄到本地的mysql8.0.26版本)
報錯內(nèi)容
error 2059: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
操作內(nèi)容
想要實現(xiàn)mysql的遠程登錄
我的嘗試,從虛擬機登錄到本地mysql
解決方法(針對mysql8.0后的版本)
方法一:
修改密碼的加密方式,對后續(xù)的新建用戶有效(在添加下述語句后,后續(xù)的新用戶加密方式默認被改為了mysql_native_password),而前期的老用戶默認密碼加密方式還是(caching_sha2_password)
找到my.ini文件,在[mysqld]下添加
default_authentication_plugin=mysql_native_password
保存,重啟mysql服務,重啟mysql服務,重啟mysql服務?。。?!生效。
老用戶需要手動修改為mysql_native_password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'; #更新一下用戶的密碼
FLUSH PRIVILEGES; #刷新權(quán)限
方法二:
沒有所謂的方法二,就跟上面的一樣。不過是,創(chuàng)建一個新用戶,指定加密方式,賦予所有權(quán)限,用新用戶連接mysql(哈哈)
-- 創(chuàng)建用戶名為hyl,設所有ip均可登錄,密碼root
create user hyl@'%' identified WITH mysql_native_password BY 'root';
-- grant給hyl賦予所有的庫和表的權(quán)限。
grant all privileges on *.* to hyl@'%' with grant option;
-- 刷新
flush privileges;
錯誤原因
新版本的MySQL新特性導致,導致認證方式有問題。
MySQL8.0版本默認的認證方式是caching_sha2_password
而在MySQL5.7版本則為mysql_native_password
學到的知識
創(chuàng)建新用戶: 其中username為自定義的用戶名;host為登錄域名,host為’%'時表示為 任意IP,為localhost時表示本機,或者填寫指定的IP地址;paasword為密碼
create user 'username'@'host' identified by 'password';
為用戶授權(quán): 其中*.第一個表示所有數(shù)據(jù)庫,第二個表示所有數(shù)據(jù)表,如果只是部分授權(quán)那就把對應的寫成相應數(shù)據(jù)庫或者數(shù)據(jù)表;username為指定的用戶;%為該用戶登錄的域名
grant 權(quán)限 on . to ‘username’@‘%’
grant 權(quán)限 on . to ‘username’@‘%’ identified by “密碼”
grant all privileges on *.* to 'username'@'%' with grant option;
- *.*第一個 * 表示所有數(shù)據(jù)庫,第二個 * 表示所有數(shù)據(jù)表
- privileges(權(quán)限列表),可以是all priveleges, 表示所有權(quán)限,也可以是select、update等權(quán)限,多個權(quán)限的名詞,相互之間用逗號分開。
- on用來指定權(quán)限針對哪些庫和表。
- to 表示將權(quán)限賦予某個用戶,@后面接限制的主機,可以是IP,IP段,域名以及%,%表示任何地方。
- 注意:這里%有的版本不包括本地,以前碰到過給某個用戶設置了%允許任何地方登錄,但是在本地登錄不了,這個和版本有關(guān)系,遇到這個問題再加一個localhost的用戶就可以了。
- WITH GRANT OPTION 這個選項表示該用戶可以將自己擁有的權(quán)限授權(quán)給別人。
舉例:
用戶名:ad,密碼:ad_pass,登陸ip:192.168.0.10
//用戶在所有登陸ip的權(quán)限
grant all on *.* to 'ad'@'%' identified by "ad_pass";
//開放管理MySQL中所有數(shù)據(jù)庫的權(quán)限
grant all on *.* to 'ad'@'192.168.0.10' identified by "ad_pass";
//開放管理MySQL中具體數(shù)據(jù)庫(test)的權(quán)限
grant all privileges on test to 'ad'@'192.168.0.10' identified by "ad_pass";
//開放管理MySQL中具體數(shù)據(jù)庫中的表(test.table1)的權(quán)限
grant all on test.table1 to 'ad'@'192.168.0.10' identified by "ad_pass"
//開放管理MySQL中具體數(shù)據(jù)庫的表(test.table1)的部分列的權(quán)限
grant select(id,se,rank) on test.table1 to 'ad'@'192.168.0.10' identified by "ad_pass";
//開放管理操作指令
grant select,insert,update,delete on test.* to 'ad'@'192.168.0.10' identified by "ad_pass";
權(quán)限的收回
#收回權(quán)限(不包含賦權(quán)權(quán)限)
REVOKE ALL PRIVILEGES ON *.* FROM 'username'@'%';
#收回賦權(quán)權(quán)限
REVOKE GRANT OPTION ON *.* FROM 'username'@'%';
#操作完后重新刷新權(quán)限
flush privileges;
結(jié)果測試(用戶‘ll’測試)
老用戶采用默認的caching_sha2_password (登錄失?。?br>
修改 ‘ll’ 的加密方式為 mysql_native_password
ALTER USER 'll'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
文章來源:http://www.zghlxwxcb.cn/news/detail-488662.html
總結(jié)
自己真的是菜的離譜,對于sql的DCL語句陌生的很,問題其實很簡單,但是我還是花了好長時間才搞懂這么一丟丟。哎,繼續(xù)加油~文章來源地址http://www.zghlxwxcb.cn/news/detail-488662.html
到了這里,關(guān)于error 2059: Authentication plugin ‘caching_sha2_password‘ cannot be loaded: /usr/lib64/mysql/plugin/的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!