mysql誤刪root用戶


在操作mysql時誤刪除root用戶,如何進行恢復

在安裝hive時候誤刪除root用戶,存在的用戶沒有權限,解決方法如下。

1、首先在/etc/my.cnf文件中 mysqlID下面添加

skip-grant-tables

用來跳過安全密碼驗證

2、在服務上重啟mysql服務

[root@master2 bin]# systemctl restart mysqld.service

3、使用mysql直接進入mysql

[root@master2 bin]# mysql

4、使用mysql數據庫

mysql> use mysql;

 5、重新添加用戶

insert into user(user,host,password,ssl_type,ssl_cipher,x509_issuer,x509_subject) values('root','localhost',PASSWORD('MyPass@123'),'','','','');

6、對新添加用戶進行授權

mysql> grant all privileges on *.* to root@"loaclhost" identified by 'MyPass@123';

此時報錯,因為處於skip-grant-tables

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

解決:

先執行

flush privileges;

再執行

mysql> grant all privileges on *.* to root@"loaclhost" identified by 'MyPass@123';
flush privileges;

此時查看新添加用戶的權限

mysql>  select * from mysql.user where user='root'\G;

此時退出mysql,在服務上的/etc/my.cnf文件上刪除掉skip-grant-tables

重啟mysql服務

[root@master2 bin]# vim /etc/my.cnf [root@master2 bin]# systemctl restart mysqld.service

重新初始化

[root@master2 bin]# schematool -initSchema -dbType mysql

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM