How to retrieve the mysql password (linux/windows)

Source: Internet
Author: User
We often forget the password of mysqlroot, so how can we find it? re-installation is too difficult to configure, next, let me introduce two methods to retrieve passwords in linux and mysql.

We often forget the mysql root password, so how can we find it? re-installation is too difficult to configure, next, let me introduce two methods to retrieve passwords in linux and mysql.

Like * UNIX version:

The following is an incorrect answer:

First stop the MySQL service and start it with the skip-grant-tables parameter:

The Code is as follows:
Shell>/etc/init. d/stop
Shell> mysqld_safe -- skip-grant-tables & in this case, you can access the MySQL command line without authorization and use SQL to reset the MySQL password: UPDATE mysql. user SET Password = PASSWORD ('... ') WHERE User = '... 'AND Host = '... ';

Flush privileges; why is it an incorrect answer? After you simply use the skip-grant-tables parameter to start the service, unless the server shields Internet access, other users except themselves may also access the database, although it takes a short time to reset the password, as the saying goes, if you are not afraid of thieves, you will be afraid of thieves. Any leaks may cause a big disaster.

The following is the correct answer:

The key point is to add the skip-networking parameter while using the skip-grant-tables parameter:

The Code is as follows:
Shell> mysqld_safe -- skip-grant-tables -- skip-networking

& After using SQL to reset the password, remember to remove skip-networking and restart the MySQL service in a normal way:

The Code is as follows:
Shell>/etc/init. d/mysqld restart

The above method needs to restart the service twice. In fact, it is more elegant. Restart the service once:

First, save the SQL statement used to a text file (/path/to/init/file ):

The Code is as follows:

UPDATE mysql. user SET Password = PASSWORD ('...') WHERE User = '...' AND Host = '...';
Flush privileges; then, use the init-file parameter to start the MySQL service,

Shell>/etc/init. d/mysql stop
Shell> mysqld_safe -- init-file =/path/to/init/file

& In this case, the password has been reset. Do not forget to delete the file to avoid leaking the password.

Tip: the parameters used in this article are passed through the command line mysqld_safe, and can also be passed through my. cnf.

For more information, see How to Reset the Root Password.

Windows version:

1. log on to the system as a system administrator.
2. Open cmd ----- net start to check whether mysql is started. If it is enabled, the net stop mysql will be stopped.
3. Install mysql in d: mysql5bin.
4. Skip the permission check and start mysql.
D: mysql5binmysqld-nt -- skip-grant-tables -- skip-networking
5. Open cmd again. Enter d: mysql5bin:
D: mysql5binmysqladmin-uroot flush-privileges password "newpassword"
D: mysql5binmysqladmin-u root-p shutdown prompts you to re-enter the password.
6. net start mysql in cmd
7. You have done it.

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.