Drip record-LinuxMysql database mistakenly deletes the root user

Source: Internet
Author: User

Drip record-LinuxMysql database mistakenly deletes the root user

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/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0skip-grant-tables[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/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: quit first;

 

5. Run the following command to log on again and set the root password.
Mysql-u rootupdate mysql. user set password = password ('yourrootpasswd') where user = 'root'; update user set host = '%' where user = 'root'; # set remote machines to access mysql, if you do not need to set 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.