【MySql】解決mysql沒有root用戶問題

發現mysql一開始沒有root用戶

先說這個問題產生的影響,這個跟解題有關,有必要說明,我的user表沒有任何一個用戶,包括root,所以一開始我要給權限,方便後續操作:

vim /etc/my.cnf
skip-grant-tables     #在[mysqld]下面添加這一行,忽略權限表


然後重啓mysql:

/etc/init.d/mysqld restart

開始解題:
先說解決步驟:
1.創建root用戶
2.給予root所有權限


過程:
1.創建root用戶:

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

localhost表示本地,mysql登入的時候,不用指定ip登入

此步驟可能會報以下錯誤,沒報錯的跳過(直接到權限那一步),用一下方法解決:

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

輸入:

flush privileges;

此時再次重新創建用戶:

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

再次報錯,這步沒報錯的也是直接跳到賦予權限那一步,報錯的以下操作:

drop user 'root'@'localhost';

再次重新創建用戶:

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

結果沒有再報錯,root用戶創建成功。
下面賦予root權限:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION; #賦予所有庫所有表操作權限

mysql> flush privileges;

mysql> exit;

到這一步沒有報錯,表明已經成功了,不過要把最開始的配置文件恢復:

vim /etc/my.cnf

刪除配置文件中的:

skip-grant-tables

退出,重啓mysql:

/etc/init.d/mysqld restart

————————————————
原文鏈接:https://blog.csdn.net/qq_37369726/article/details/101944373

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章