首页 > 数据库技术 > 详细

误删mysql root账户

时间:2019-11-27 12:29:39      阅读:64      评论:0      收藏:0      [点我收藏+]

看这个账户有点碍眼就删除了,结果异常了
mysql> select user,host from mysql.user;
+---------------+-------------+
| user | host |
+---------------+-------------+
| repmha | 192.168.5.% |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-------------+
4 rows in set (0.00 sec)

mysql> drop user root@‘localhost‘;
Query OK, 0 rows affected (0.01 sec)

登录异常:库中已没了root用户
[root@test110 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

修改异常:现在本身就没root用户所以没法修改,无论哪种方式修改,都要先有
mysql> set password for ‘root‘@‘localhost‘ = password(‘123456‘);
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED WITH mysql_native_password BY ‘123456‘;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

1、修改my.cnf
vi /etc/my.cnf
--添加
skip-grant-tables
2、重启
service mysqld restart

3、登录
[root@xxxx ~]# mysql -uroot -p123456
mysql> use mysql;
Database changed
mysql> select user , host from user;
+---------------+-------------+
| user | host |
+---------------+-------------+
| monitor | 192.168.5.% |
| repmha | 192.168.5.% |
| mysql.session | localhost |
| mysql.sys | localhost |
+---------------+-------------+
4 rows in set (0.00 sec)
4、重新添加,有时候会出现错误,可以先flush下
mysql> grant all on *.* to root@‘localhost‘ identified by ‘123456‘;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

5、root又回来了
mysql> select user , host from user;
+---------------+-------------+
| user | host |
+---------------+-------------+
| monitor | 192.168.5.% |
| repmha | 192.168.5.% |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-------------+
5 rows in set (0.00 sec)

6、删除 /etc/my.cnf中 skip-grant-tables ,再重启 service mysqld restart


没事别瞎胡整,删除动作很危险。

误删mysql root账户

原文:https://www.cnblogs.com/ritchy/p/11940485.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!