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

 

转载于:https://www.cnblogs.com/learn-bigdata/p/10454976.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值