Change the root password and restore the MySQL root User

Source: Internet
Author: User
Tags mysql tutorial

I accidentally deleted the MySQL root Account by changing the root password and restoring the MySQL root User. What should I do? "And" I lost my root password? If this problem occurs, why do you need to back up data, reinstall MySQL, and restore all database files? What should we do? Now we can find a better way for you.

Change the root password and restore the root user of the mysql tutorial
I accidentally deleted the root account of mysql. What should I do? "And" I lost my root password? If this problem is encountered, why do you need to back up data, reinstall mysql, and restore all database tutorial files? What should we do? Now we can find a better way for you.

1. Stop mysql,
2. Server Permissions
C: www.bKjia.c0mbinmysqld-nt.exe -- skip-grant-tables
Where c: www. bKjia. c0m is mysql 'instalation directory.
For linux, run the following command:
/Usr/local/mysql/bin/mysqld_safe -- skip-grant-tables -- user = root -- skip-networking
3. Connect to the server and use the exsisting account (root or some otherif root accounts are deleted ).
C: www.bKjia.c0mbinmysql.exe-u user
Or
/Usr/local/mysql/bin/mysql-u user

4. Change the mysql query Password
Update mysql. user set password = password ('newpwd') where user = 'root ';
Or recreating user:
Create user root identified by password 'newpwd ';
Grant all privileges on *. * to 'root' @ 'localhost' identified by 'newpwd' with grant option max_queries_per_hour 0 max_connections_per_hour 0 max_updates_per_hour 0 max_user_connections 0;

5. Refresh Permissions
Flush privileges;

6. Restart the server
OK. You can retrieve the mysql root Password.

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.