Mysql deletes the root user by mistake or forgets the root password. Solution _ MySQL

Source: Internet
Author: User
Mysql deletes the root user by mistake or forgets the root password. Solution: bitsCN.com Solution 1:

Go to another server with Mysql installed (the premise is to know the root user password of Mysql on the server), open [Mysql installation directory/var/mysql], and set the user. frm, user. MYD, user. copy the MYI files to the [Mysql installation directory/var/mysql] directory on the problematic server. Then restart the server.

Solution 2:

Modify your my. ini or my. cnf file and add the following line under [mysqld]
Skip-grant-tables
Then save and restart the MySQL service. Now you can log on to the database with any user name and password.

(1) If the root user is accidentally deleted, use the following statement to create the root user:

Insert into user set Host = 'localhost', User = 'root', Password = Password ('000000'), 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 ';

(2) If you forget the password of the root user, use the following statement to change the root password:

Update user set Password = Password ('000000') where User = 'root ';

Mysql deletes the root user by mistake

1. stop the mysqld process first.

# Killall mysqld entering mysql
#/Usr/local/mysql/bin/mysql

Enter mysql without loading grant_tables
# Mysqld_safe

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.