System:
CentOS Release 6.5 (Final)
Kernel:
2.6.32-431.el6.x86_64
MySQL version:
5.5.28-log Source Distribution
Operation Steps:
1. Stop the MySQL service
#service mysqld Stop
2. Enter MySQL in safe mode
#mysqld_safe--skip-grant-tables &
#mysql-u root-p \ The password is empty at this time
3. Rebuild Root
Mysql>use MySQL;
Mysql>insert into User (Host,user,password)
->values (' localhost ', ' root ', password (' password ')); \ The password here can be set later
4. Assigning permissions to the root user
Update user set host= ' localhost ', select_priv= ' y ', insert_priv= ' y ', update_priv= ' y ', alter_priv= ' y ', delete_priv= ' y ', create_priv= ' y ', drop_priv= ' y ', reload_priv= ' y ', shutdown_priv= ' y ', process_priv= ' y ', file_priv= ' y ', grant_priv= ' y ', references_priv= ' y ', index_priv= ' y ', create_user_priv= ' y ', show_db_priv= ' y ', super_priv= ' y ', create_tmp_table_priv= ' Y ', lock_tables_priv= ' y ', execute_priv= ' y ', repl_slave_priv= ' y ', repl_client_priv= ' y ', create_view_priv= ' y ', show_ view_priv= ' y ', create_routine_priv= ' y ', alter_routine_priv= ' y ', create_user_priv= ' y ', event_priv= ' y ', trigger_priv= ' Y ', create_tablespace_priv= ' y ' where user= ' root ';
- Mysql> flush Privileges//Refresh
- Log out of MySQL, restart the MySQL service, and restore the root account to completion
Note: When assigning permissions to the root user, the Event_priv, Trigger_priv, create_tablespace_priv Three permissions must be added, or even if the root user is restored, you cannot give all privileges permissions to other users.
How to restore the root account after MySQL mistakenly deleted root