MySQL forgot password

Source: Internet
Author: User
Tags lost password mysql login


Solution 1:http://www.2cto.com/database/201312/264229.html

MySQL root account password default is empty, often have to change the password after forgetting the password. If you forgot your root account password, how do I change the password? Here's a practical way to fix this problem by changing the password in MySQL Safe mode (skip permission check). This article is about the Windows environment and Linux environment in the introduction of MySQL Forgot Password Change password method, hope to help beginners to solve the problem of lost password.

MySQL Reset password under Windows

Typically, MySQL is installed as a Windows service run.

1. Start cmd Command window:

# Turn off MySQL service
D:\MYSQL\BIN>SC Stop MySQL

# start MySQL in safe mode
D:\mysql\bin>mysqld--skip-grant-tables
2. Do not close, and then start a new cmd command window:

# Log in to MySQL database
D:\mysql\bin>mysql-u root-p

mysql> use MySQL;
mysql> Update user Set Password=password ("123456") where user= "root";
mysql> flush Privileges;
3, close the above two windows, start the MySQL service

# Start the MySQL service
C:\>SC start MySQL


MySQL Reset password under Linux

The password reset operation under Linux is similar to that under Windows.

# Stop MySQL Service
[[email protected] ~]#/etc/init.d/mysql stop

# start MySQL in safe mode
[Email protected] ~]#/usr/local/mysql/bin/mysqld_safe--skip-grant-tables &

# Log in to MySQL
[Email protected] ~]# mysql-u root-p

mysql> use MySQL;
mysql> Update user Set Password=password ("123456") where user= "root";
mysql> flush Privileges;

# Start the MySQL service
[[email protected] ~]#/etc/init.d/mysql start

Solution 2:http://www.cnblogs.com/allenblogs/archive/2010/08/12/1798247.html

1. First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily.
Because the MySQL database is completely password-protected during the reset of the root password of MySQL
Status, other users can also log in and modify MySQL information arbitrarily. MySQL can be used to
and stop Apache and all user processes to implement the server's quasi-security
State. The safest state is to operate on the console of the server and unplug the network cable.
2. To modify the login settings for MySQL:
# VI/ETC/MY.CNF
Add a sentence to the paragraph in [mysqld]: Skip-grant-tables
For example:
[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Skip-grant-tables
Save and Exit VI.
3. Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]
4. Log in and modify the root password of MySQL
#/usr/bin/mysql
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3 to server version:3.23.56
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.
mysql> use MySQL;
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a
Database changed
mysql> UPDATE user SET Password = Password (' New-password ') WHERE user = ' root ';
Query OK, 0 rows Affected (0.00 sec)
Rows matched:2 changed:0 warnings:0
mysql> flush Privileges;
Query OK, 0 rows affected (0.01 sec)
Mysql> quit
Bye
5. Change MySQL login settings back
# VI/ETC/MY.CNF
Delete the skip-grant-tables you just added in the paragraph [mysqld]
Save and Exit VI.
6. Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]

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.