Mysql 下建立root使用者,mysql建立root使用者

來源:互聯網
上載者:User

Mysql 下建立root使用者,mysql建立root使用者

在linux下安裝了mysql之後出現錯誤,剛開始以為就是沒有密碼的問題,按照這篇文章進行了修改:linux下mysql 初次登陸修改密碼  修改之後應該沒錯,但再次啟動服務root登入還是不行,下面的就是出現的問題和解決過程:


 mysqld_safe--skip-grant-tables&mysql-uroot mysql
mysql> select * from user;
Empty set (0.00 sec)
mysql> select USER();
+--------+
| USER()|
+--------+
| root@ |
+--------+
1 row in set (0.00 sec)

這裡驚奇的發現居然沒有root使用者,user表裡面是空的,還是第一次遇到這種問題的。

由於 mysqld_safe --skip-grant-tables裡面是不能用grant的,於是想到了手動insert插入root使用者:

**為了大家方便這裡提供一些說明:第一個值是host,第二個為user這兩項是必填項,password("my_password")這裡進行密碼的設定,MY_PASSWORD 就是密碼 ,而'Y'有28個,之後有1個enum和3個blob 可以為空白,也就是這裡的4個Null 字元,int類型有4個,預設值為0

INSERTINTO user VALUES('%','root',password('MY_PASSWORD'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0)

這裡要主要的是第3個欄位密碼處要用password('密碼'),因為mysql中密碼是要經過編碼的,不是直接字串儲存的。

接著在殺掉所有mysql進程,之後正常重啟mysql,即可用root使用者登入

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.