码迷,mamicode.com
首页 > 数据库 > 详细

mysql误删root用户

时间:2019-03-01 12:53:43      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:mysql数据库   rest   localhost   iss   使用   ror   sql   解决   用户   

在操作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

技术图片

技术图片

 

mysql误删root用户

标签:mysql数据库   rest   localhost   iss   使用   ror   sql   解决   用户   

原文地址:https://www.cnblogs.com/learn-bigdata/p/10454976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!