How to reset the root password of Mysql in Windows if you forget it

How to reset the root password of Mysql in Windows if you forget it

My machine environment:

Windows 2008 R2

MySQL 5.6

Search "Forgot Mysql root password under Windows" on Baidu and find a lot of solutions. Most of them are similar, but the more classic one is the one on Baidu Wenku [1], which is well illustrated and well organized. Follow the instructions in this article immediately.

The specific operations are as follows:

If you add the MySQL environment variables in the following steps, you can directly run the MySQL commands. Otherwise, you must go to the bin directory of the MySQL installation directory to operate.

Here are the steps:

1. Stop the mysql service (as an administrator, run in cmd command line) net stop mysql

2. Use the mysqld –skip-grant-tables command to start the mysql database

D:\>net stop mysql MySQL service is stopping. MySQL service has been stopped successfully.

D:\>mysqld --skip-grant-tables

3. Without closing the above window, open a new cmd window, enter mysql -u root, and press Enter directly

D:\>mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.26-rc-community MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> update mysql.user set password=password('aaa') where user='root';

The password can be written by yourself.

Query OK, 1 row affected (0.02 sec) Rows matched: 2 Changed: 1 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec) mysql>

4. Open the Task Manager, stop the mysql and mysqld processes, use net start mysql to start the mysqld service, and then you can use the root user and root password to enter the database

mysql -u root -p aaa

Additional notes:

1. The mysqld usage instructions can be obtained and viewed using the following command:

mysqld --verbose --help > d:\mysqld_help.txt

The help for --skip-grant-tables is:

--skip-grant-tables Start without grant tables. This gives all users FULL ACCESS to all tables!

So we can use mysql -uroot without a password to log in to mysql directly, and we can modify any table.

In my practice, I use mysqld --skip-grant-tables to start mysql, and I can log in with mysql -u root -p with an empty password. The password change will also prompt success. However, when I start mysql normally, I still cannot log in with the new password. I thought that since I couldn't find the answer on Chinese websites, I would try to look for the answer on foreign websites. So I searched for the keyword "mysql 5.6 forget root password" and found the answer in a document on mysql.com called "B.5.3.2 How to Reset the Root Password" [2].

The specific steps are as follows:

(1) Stop MySQL

If running as a service, stop the MySQL service in the service management tool. Or run the following command in the console.

net stop mysql56

If it is not running as a service, kill the mysqld process in Task Manager.

(2) Create a text file and write the following content. MyNewPass is your new password

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

(3) Save as c:\init.txt

(4) Execute the following command in the console window

mysqld --init-file=C:\\init.ini

Notice:

1) If you have added the MySQL environment variables, you can run MySQL commands directly. Otherwise, you must go to the bin directory of the MySQL installation directory to operate.

2) If you installed MySQL using the MySQL installation wizard, you need to add the --defaults-file parameter. The command is as follows:

mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" --init-file=C:\\init.ini

The --defaults-file parameter can be obtained from the service management: Start > Control Panel > Administrative Tools > Services, find the MySql service, right-click, select the Properties tab, and the "Execution Path" contains the --defaults-file parameter.

(5) After the system starts successfully, close Mysql and delete the init.ini file.

References:

[1] http://wenku.baidu.com/view/5c0d2164e55c3b3567ec102de2bd960590c6d9c0

[2]https://dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html

The above is the method of resetting the root password of Mysql under Window that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • What should I do if I forget my MySQL password? How to reset MySQL root password
  • Detailed method for forgetting the root password or resetting the password in Mysql 5.7
  • How to reset the root password in mysql8.0.12
  • How to reset MySQL root password under Windows
  • Reset mysql root password in linux system
  • How to reset the root user password of MySQL database if you forget it [Graphic]
  • Complete steps to reset the root user password in mysql8
  • How to solve the problem "Unknown column 'password" when resetting MySQL root password
  • The easiest way to reset mysql root password
  • A practical record of MySql resetting the root password and failing

<<:  How to create and run a Django project in Ubuntu 16.04 under Python 3

>>:  js to implement collision detection

Recommend

Computed properties and listeners details

Table of contents 1. Calculated properties 1.1 Ba...

Example of using CSS to achieve floating effect when mouse moves over card

principle Set a shadow on the element when hoveri...

Detailed explanation of pid and socket in MySQL

Table of contents 1. Introduction to pid-file 2.S...

MySQL limit performance analysis and optimization

1. Conclusion Syntax: limit offset, rows Conclusi...

Native JS to implement sharing sidebar

This article shares a sharing sidebar implemented...

HTML Tutorial: title attribute and alt attribute

XHTML is the basis of CSS layout. jb51.net has al...

How to elegantly implement WeChat authorized login in Vue3 project

Table of contents Preface Prepare Implementation ...

Introduction to the use and advantages and disadvantages of MySQL triggers

Table of contents Preface 1. Trigger Overview 2. ...

How to view image information in Docker

In this article, we will need to learn how to vie...

How to query whether the mysql table is locked

Specific method: (Recommended tutorial: MySQL dat...

MySQL data analysis storage engine example explanation

Table of contents 1. Introduce cases 2. View the ...

Vue custom components use event modifiers to step on the pit record

Preface Today, when I was using a self-written co...

Mysql sets boolean type operations

Mysql sets boolean type 1. Tinyint type We create...

Detailed graphic explanation of how to use svg in vue3+vite project

Today, in the practice of vue3+vite project, when...