Accidental deletion mysql root account

Look a little unsightly on this account is deleted, the result of abnormal
MySQL> the SELECT the User, Host from the mysql.user;
+ --------------- + ---------- + ---
| the 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)

Log exception: the library did not have a root user
[root @ test110 ~] # MySQL-uroot--p123456
MySQL: [Warning] A password ON the Using the Command Line interface at The CAN BE in the insecure.
ERROR 1045 (28000): Access denied for the User ' root '@' localhost '(using password: YES)

Modify an exception: there is no root user itself now so I can not modify, amend Either way, they have to have
MySQL> the SET password for 'root' @ 'localhost' = password ( '123456');
ERROR 1290 (HY000): The MySQL server is running with the --skip -grant-tables option so it can not 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, modify the my.cnf
VI /etc/my.cnf
- Add
Skip-Grant-Tables
2, restart
service mysqld restart

3, log
[XXXX the root @ ~] # -uroot--p123456 MySQL
MySQL> MySQL use;
Database changed
MySQL> SELECT User, Host from User;
+ --------------- + - + -----------
| the User | Host |
+ --------------- + ------------- +
| Monitor |. 192.168.5% |
| repmha |. 192.168.5% |
| mysql.session | localhost |
| mysql.sys | localhost |
+ --------------- + --- + ----------
4 rows in the SET (0.00 sec)
4, re-add, sometimes an error occurs, you can flush down
mysql> grant all on *. * to root @ 'localhost' identified by '123456';
Query the OK, 0 rows affected, 2 Represents 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, delete /etc/my.cnf in skip-grant-tables, and then restart service mysqld restart


All right Nobody is allowed to Hu whole, delete the action is very dangerous.

Guess you like

Origin www.cnblogs.com/ritchy/p/11940485.html