MySQL forgot password

Source: Internet
Author: User

Preface:

Before learning MySQL, sometimes forget root password problem, there is a lot of information on the Internet, but are not very complete, here I through countless experiments, share a reset root password complete method.

Windows platform:

1th Step: Start menu, Control Panel, management tools, find the MySQL server, and stop it, if the server is not running as a service, you may need to use Task Manager to force stop it.

2nd step: Create a text file Mysql-ini.txt and enter set PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' NewPassword ') in the text file;

Save the Mysql-ini.txt file to any path for convenience. In this example, the save path is C:/mysql-ini.txt

3rd Step: Open the Console window and enter the DOS prompt:

Start menu, run-to-cmd

Assuming that you have installed the MySQL service in the C:/mysql path, execute the command at the DOS command prompt:

C:\> C:/mysql/bin/mysqld-n--init-file=c:/mysql-ini.txt

4th step: Restart the MySQL service (this time MySQL executes the content in Mysql-ini.txt, change the root user password)

5th step: According to theory, MySQL password reset has been successful, you can use the new password to log in to the MySQL service, after the last login success, do not forget to delete the junk file Mysql-ini.txt

(Password settings may not be successful, try several times as described above)

UNIX platforms:

1th step: Log on to the system as the UNIX root user or as the same as the running Mysqld server.

2nd step: Locate the. pid file that contains the server process ID. The exact location and name of the file change depends on your distribution, hostname, and configuration. Common locations are/var/lib/mysql/,/var/run/mysqld/

and/user/local/data/. In general, the file name extension is. PID and starts with the hostname of the msyqld or system

3rd Step: Use the path name of the. pid file in the following command, to mysqld the process to a normal kill, you can stop the MSYQL server:

Shell> kill ' Cat/mysql-data-directory/host_name.pid '

Note: The cat command uses "'" instead of "", which brings the input of cat into the KILL command.

4th step: Create a text file and place the following command in the file

SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Youpassword ');

Save the file with any name, in this case the file is ~/mysql-ini

5th step: Restart the MySQL server with the special '--init-file = ~/mysql-ini ' option:

Shell> Msyqld_safe--init-file=~/mysql-ini &

Restart the MySQL service (this time MySQL executes the content in Mysql-ini.txt, changing the root user password)

6th step: According to theory, MySQL password reset has been successful, you can use the new password to log in to the MySQL service, after the last login success, do not forget to delete the junk file Mysql-ini.txt

(Password settings may not be successful, try several times as described above)

MySQL forgot password

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.