天天看點

ubuntu和deepin安裝mysql-server後無法進入,update user set authentication_string=password(“密碼“)文法報錯

ubuntu19

  1. 固态硬碟到手後,安裝ubuntu19,之後安裝好mysql,但是在用指令登陸資料庫的時候報錯:
sudo apt install mysql-server#安裝MySQL
mysql -u root -p#登入
access denied for user [email protected]#報錯
           
  1. 于是我在mysqld.cnf檔案末尾添加

    skip-grant-tables

    ,儲存之後重新開機mysql 服務并登入,直接按enter鍵進入了資料庫
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
#在檔案末尾添加skip-grant-tables
service mysql restart #重新開機mysql服務
mysql -u root -p#登入
           

3.于是令authentication=’’,将

skip-grant-tables

注釋重新開機mysql服務,然後也可以登陸資料庫

update user set authentication_string='' where user='root';#root不設定密碼
service mysql restart #在這之前記得要注釋掉skip-grant-tables
           
  1. 如果我們想給root使用者設定密碼怎麼辦呢?
update user set plugin='mysql_native_password' where user='root'; #更改加密方式
alter user 'root'@'localhost' IDENTIFIED BY '123456';#設定密碼
FLUSH PRIVILEGES;
           
  1. 然後就可以使用密碼登陸了(mysql 的 root使用者中有幾個 password="", 為了安全起見用 delete 指令删除就行)

deepin15 (已經驗證,沒有錯誤)

  1. 在deepin 中安裝MySQL(MariaDB):
sudo apt install mysql-server
           
  1. 登入mysql(MariaDB),在root權限下可以直接登入,當然也可以想上文Ubuntu中一樣加入skip-grant-tabels
sudo mysql -u root -p
           
  1. 可以看到新版的MariaDB中使用unix-socket加密,我們将plugin修改為mysql_native_password
use mysql
update user set plugin='mysql_native_password' where user='root';
           
  1. 然後我們就可以設定密碼了
update user set password=password('123456') where user='root'
update user set authentication_string=password('123456') where user='root'
如果上面報錯的話,可以嘗試執行:
alter user 'root'@'localhost' identified by '123456'
           
  1. 重新開機服務,登陸
exit
service mysql restart#重新開機服務
mysql -u root -p #登陸
           
  • 注意雖然作者竭力想寫地準确無錯,但仍會有所忽略,請多包含
  • 重點就是将root使用者的加密方式plugin修改為mysql_native_password(真的嗎?好像我在建立普通使用者的時候不用诶?等我下一次重裝資料庫的時候再來驗證吧,現在我真的不想驗證,要吐了)
  • 這是作者第二次修正了(ubuntu部分),歡迎各位讀者指正

本文參考:mysql8.XXX版本以後重置密碼,修改加密方式解決Authentication plugin ‘XXX’ cannot be loaded問題

擴充閱讀:mysql建立普通使用者,并用其建立資料庫