Bit record--linux MySQL database mistakenly delete root user

Source: Internet
Author: User

Reprint please indicate source: http://blog.csdn.net/cywosp/article/details/42145779


In Linux sometimes installing MySQL will appear without root user condition, or the root account is deleted from the Mysql.user table mistakenly, so that many permissions can not be controlled. The workaround is to recreate the root user and grant all permissions, as follows:

1. Modify the/etc/my.conf file to add Skip-grant-tables

[mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/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/mysqld.pid
2. Restart the MySQL service
/etc/init.d/mysqld restart
3. Use the following command to log in to MySQL without a password
MySQL
4. Re-add the root user after login
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 ';
quit first: quit;
5. Use the following command to log in again to set the root password
Mysql-u Root
Update Mysql.user set Password=password (' yourrootpasswd ') where user= ' root ';
Update user Set host = '% ' where user = ' root '; #设置远程机器可访问mysql, if you don't need to set
Flush privileges;
Quit
6. Modify the/etc/my.conf file, remove the skip-grant-tables, and restart MySQL
/etc/init.d/mysqld Restart
7. Normal everything OK

Reference:
[1]. http://jingyan.baidu.com/article/7c6fb4287c613880642c9003.html




Bit record--linux MySQL database mistakenly delete root user

Related Article

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.