MySQL forgot the account password.

Source: Internet
Author: User
Tags mysql command line

First, disable MySQL

Use the command line to start MySQL (usually find the mysql. ini file)

On Windows, you can view the MySQL process parameters in the mysql. ini file. Click here for details.

Add the -- skip-grant-tables parameter at the end of the MySQL command line.

Other methods:

1. Send the kill command to the mysqld server to disable the mysqld server (not kill-9). The files that store the process ID are usually located in the directory of the MySQL database.
Killall-term mysqld
You must be a Unix root user or an equivalent user on the server you run to perform this operation.
2. Use the '-- skip-grant-tables' parameter to start mysqld. (Linux/usr/bin/safe_mysqld -- skip-grant-tables, Windows c: \ mysql \ bin \ mysqld -- skip-grant-tables)

3. log on to the mysqld server without a password,
> Use MySQL
> Update user SET Password = PASSWORD ("new_pass") where user = "root ";
> Flush privileges;
. You can also do this: 'mysqladmin-H hostname-u user password' new password ''.

4. Load the permission table: 'mysqladmin-H hostname flush-Privileges ', or use the SQL command 'flush privileges '.
5. killall-term mysqld
6. log in with a new password

Correct: the actual operations on windows are as follows:
1. Disable running MySQL.
2. Open the DOS window and go to the MySQL \ bin directory.
3. Enter mysqld-NT -- skip-grant-tables and press Enter. If no prompt is displayed, it is correct.
4.Open another DOS window(Because the DOS window just now cannot be moved), go to the MySQL \ bin directory.
5. Enter MySQL and press Enter. If yes, a MySQL prompt is displayed.>
6. Connect to the permission database> use MySQL; (> is the original prompt, don't forget the last semicolon)
6. Change the password:> Update user SET Password = PASSWORD ("123456") where user = "root"; (do not forget the last semicolon)
7. Refresh permissions (required steps)> flush privileges;
8. Exit> \ q
9. log out of the system, log on to MySQL, and log on to MySQL with the username "root" and the new password "123456.

It is said that you can directly modify the user table file:
Close mysql. In Windows, open MySQL \ data \ mysql. There are three file users. FRM, user. MYD, user. myi finds a MySQL with a password and replaces these three files. If the user table structure has not been changed, no one will change it. Replace the user. MYD.
You can also directly edit user. MYD and find a hexadecimal editor. ultraedit has this function. Close MySQL and enable user. MYD. Change the eight characters after the root user name to 565491d704013245, and the new password is 123456. Or change the hexadecimal numbers corresponding to them (one character on the left corresponds to two numbers) to 00 02 02 02 02 02 02 02 02 02. This is an empty password, the asterisk * is displayed on the right of the editor, which looks like a decimal point. Restart MySQL and enter root and your new password.
Today, MSSQL has something to do. Because it was installed a long time ago, I forgot the SA password. Although I can use Windows for authentication, I cannot connect to MSSQL using PHP, so Google found the solution.

Use the Windows authentication mechanism, and then
Run the following command:
Exec sp_password null, 'newpass', 'sa'

Example
A. Change the logon password without the original password
The following example shows how to change the password for logging on to Victoria to 123.
Exec sp_password null, '123', 'sa'

B. Change the password
In the following example, the password for logging on to Victoria is changed from 123 to 456.
Exec sp_password '000000', '000000'

In addition, I found a problem, that is, the authentication mechanisms for Windows and SQL Server are somewhat different.
Windows Authentication

Server address logon result
127.0.0.1 OK
Localhost wrong
. OK

SQL Server Authentication

Server address logon result
127.0.0.1 OK
Localhost wrong
. Wrong

In addition, record the Retrieval Method for forgetting the MySQL password.
If MySQL is running,
Killall-term mysqld (if it is windows, call the process manager directly and end it)
Start mysq in safe mode:
/Usr/bin/safe_mysqld -- skip-grant-tables &
(In Windows, MySQL is installed on the disk/MySQL/bin/safe_mysqld -- skip-grant-tables)
You can access MySQL without a password.
Then
> Use MySQL
> Update user SET Password = PASSWORD ("new_pass") where user = "root ";
> Flush privileges;
Kill MySQL again and start MySql in a normal way

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.