Solution for deleting the root user of MySQL by mistake in Linux
I started to be unfamiliar with the Linux interface. Maybe I accidentally deleted the root user. What should I do?
1. # killall mysqld to kill all mysql Processes
2. # mysqld_safe -- skip-grant-tables & enter mysql Security Mode
3. log on to the mysql console in the previous step and enter mysql-p.
Enter the system as a root user because the root user exists by default. We deleted the mysql table by mistake.
4. Prompt, Enter password:
Enter the root user password, which is generally 123456 or root. If the password fails, change the root user password under liunx.
5. mysql> use mysql to use mysql tables
6. mysql> insert into user set user = 'root', ssl_cipher = '', x509_issuer ='', x509_subject = '';
Create a root user
7. msyql> 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', region = 'y ',
Create_user_priv = 'y' where user = 'root ';
Set root User Permissions. All permissions are 'y', that is, they have the highest permissions.
8. mysql> exit to exit the mysql database.
9. # service mysqld restart Database
10. # mysql-u root-p press [enter] and press [enter] because we didn't set the password for the root user before, and now all users use the root user to enter and change the password
11. mysql> update user set password = password ('000000') where user = 'root'; modify the root password
12. mysql> flush privileges; refresh user permissions. You can restart mysql here.
13. mysql> exit to exit the mysql database.
So far, the success is achieved.
Reference: Compile and install MySQL 5.6.14 in CentOS 6.4
For more details, please continue to read the highlights on the next page: