Trace records-delete the root user by mistake in the Linux Mysql database, mysqlroot
Reprint please explain the source: http://blog.csdn.net/cywosp/article/details/42145779
In Linux, sometimes Mysql is installed without a root user, or the root account is accidentally deleted from the mysql. user table, which causes many permissions to be uncontrollable. The solution is to recreate the root user and grant all permissions as follows:
1. Modify the/etc/my. conf file and add skip-grant-tables
[Mysqld]
Datadir =/var/lib/mysql
Socket =/var/lib/mysql. sock
User = mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
Symbolic-links = 0
Skip-grant-tables
[Mysqld_safe]
Log-error =/var/log/mysqld. log
Pid-file =/var/run/mysqld. pid
2. Restart the mysql service.
/Etc/init. d/mysqld restart
3. Use the following command to log on to mysql without a password
Mysql
4. After logging in, add the root user again.
Use mysql;
Insert into user set user = 'root', ssl_cipher = '', x509_issuer ='', x509_subject = '';
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' where user = 'root ';
Exit first: quit;
5. Run the following command to log on again and set the root password.
Mysql-u root
Update mysql. user set password = password ('yourrootpasswd') where user = 'root ';
Update user set host = '%' where user = 'root'; # set remote machine access to mysql.
Flush privileges;
Quit;
6. Modify the/etc/my. conf file, remove skip-grant-tables, and restart mysql.
/Etc/init. d/mysqld restart
7. If it is normal, everything is OK.
Refer:
Http://jingyan.baidu.com/article/7c6fb4287c613880642c9003.html.