Four methods for changing the root password for mysql in Windows _ MySQL

Source: Internet
Author: User
This article mainly introduces four methods for changing the root password of mysql in windows. you can choose one based on your actual situation, if you are interested, you can refer to MySQL as a Relational Database Management System. In terms of WEB applications, MySQL is one of the best RDBMS (Relational Database Management System) applications. PHP and Apache can be used together to form a good development environment. Therefore, it is widely used. Many people will encounter MySQL password changes, such as the password is too simple, forget the password and so on. Here I will teach you several ways to change the MySQL password. Here, we will change the root password as an example. the operating system is windows.

First, we need to declare that, in most cases, modifying MySQL requires the root permission in mysql. Therefore, users cannot change the password unless they request the administrator.

Method 1:Use the set password command

1. open the terminal win + r and enter cmd and press enter;

2. use mysql-u username-p to specify the root user to log on to MySQL. enter the password and press enter.

3. modify the MySQL root user password. format:

Mysql> set password for username @ localhost = password ('New password ');

Example:

mysql> set password for root@localhost = password('shapolang');

In the preceding example, the user root password is changed to shapolang;

Log on again and enter the new password shapolang;

Method 2:Use mysqladmin

1. open the terminal win + r and enter cmd and press enter;

2. modify the MySQL root user password format: mysqladmin-u username-p old password new password

Example:

mysqladmin -uroot -pshapolang password 123456

In the preceding example, change the user's original root password shapolang to the new password 123456.
Log on again and enter the new password 123456;

Method 3:Use UPDATE to directly edit the user table

1. log on to MySQL first.

2. connect to the permission database:

use mysql; 。

3. change the password:

Update user set password = password ("shapolang") where user = "root"; (do not forget the last Plus points ).

4. refresh permission (required ):

flush privileges;

Log on again and enter the new password shapolang;

Method 4:Forgot root password

1. disable the running MySQL service.

2. open the DOS window and go to the mysql \ bin directory.

3. enter mysqld -- skip-grant-tables and press enter.-- Skip-grant-tablesThis means that the permission table authentication is skipped when the MySQL service is started.

4. open another DOS window (because the DOS window can no longer be moved), enter mysql and press Enter. if it succeeds, the MySQL prompt> will appear.

6. connect to the permission database:

 use mysql; 。

7. change the password:

Update user set password = password ("root") where user = "root"; (do not forget the last Plus points ).

8. refresh permission (required ):

flush privileges; 

9. exit quit.
Restart the mysql service and use the username root and the new password root to log on;

Note:
If mysql-related commands cannot be executed, you can add the directory where the commands are located to the environment variables, or enter the directory where the commands are located before executing them.

The above are four methods for changing the root password for mysql in Windows _ MySQL content. For more information, see PHP Chinese network (www.php1.cn )!

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.