How to solve the problem that MySQL forgets the root password

Source: Internet
Author: User


Solution for MySQL to forget the root password: www.2cto.com 1. if you forget the MySQL root Password, use the following methods to reset the password: 1. KILL the MySQL process in the system; killall-TERM mysqld 2. run the following command to start MySQL without checking its permissions: safe_mysqld -- skip-grant-tables & 3. then use the empty password to log on to MySQL as the root user; mysql-u root 4. modify the password of the root user; mysql> update mysql. user set password = PASSWORD ('new password') where User = 'root'; mysql> flush privileges; mysql> quit restart MySQL to log on with the new password. II. mySQL password recovery method 2 it is possible that your system does not have the safe_mysqld Program (for example, I am using the ubuntu operating system, mysql installed with apt-get). The following method can be restored: 1. stop mysqld;/etc/init. d/mysql stop (You may have other methods to stop running mysqld) 2. run the following command to start MySQL without checking its permissions: mysqld -- skip-grant-tables & 3. then use the empty password to log on to MySQL as the root user; mysql-u root 4. modify the password of the root user; mysql> update mysql. user set password = PASSWORD ('newpassword') where User = 'root'; mysql> flush privileges; mysql> quit restart MySQL /Etc/init. d/mysql restart can use the new password newpassword to log on. Solution for www.2cto.com in Windows: 1. Edit the MySQL configuration file: my. ini usually contains the MySQL configuration file under the MySQL installation directory. Add the following line at the end of the configuration file: skip-grant-tables save and exit editing. 2. Restart the MySQL service and run: net stop MySQL net start MySQL in the command line. 3. Set the new ROOT password and then execute it in the command line: mySQL-u root-p MySQL or mysql-u root-p directly press enter without a password to enter the database. Execute use mysql in the command line. Now, run the following statement to update the root password to: update user set password = password ("root") where user = "root "; (Note: In this case, you do not need to use the mysqladmin-u root-p password 'your new password' command to change the password, because 'skip-grant-tables 'is configured. If you do not believe it, you can try it out. It will certainly report the following error: F: \ Documents and Settings \ long> mysqladmin-u root-p password 'root' Enter password: Warning: single quotes were not trimmed from the password by your command line client, as you might h Ave expected. mysqladmin: You cannot use 'Password' command as mysqld runs with grant tables disabled (was started with -- skip-grant-tables ). use: "mysqladmin flush-privileges password '*'" instead) exit MySQL. 4. Restore the configuration file and restart the service www.2cto.com. Then modify the MySQL configuration file and delete the added line 'skip-grant-tables. Restart the MySQL service again and the password is changed. Try the new password root and log on to mysql again.

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.