The password of the root account of MySQL is empty by default. It is often forgotten after the password is changed. If you forget the password of the root account, how can you change the password? Here is a feasible method to solve this problem by changing the password in MySQL security mode (skipping the permission check. This article introduces how to change the password when MySQL forgets the password in Windows and Linux respectively, hoping to help beginners solve the headache of losing the password.
Reset the password of MySQL in Windows
MySQL is usually installed as a Windows service.
1. Start the cmd command window:
# Disable MySQL service D: \ MySQL \ bin> SC stop mysql # Start MySQLD: \ MySQL \ bin> mysqld -- skip-grant-tables in Safe Mode
2. Do not close it. Start a new cmd command window:
# Log on to the MySQL database D: \ MySQL \ bin> mysql-u root-pmysql> use mysql; mysql> update user set password = password ("123456 ") where user = "root"; mysql> flush privileges;
3. Close the preceding two windows and start the MySQL service.
# Start MySQL service C: \> SC start mysql
Reset the password of MySQL in Linux
In Linux, password resetting is similar to in Windows.
# Stop the MySQL service [root @ www ~] #/Etc/init. d/mysql stop # Start MySQL in safe mode [root @ www ~] #/Usr/local/mysql/bin/mysqld_safe -- skip-grant-tables &
# Log on to MySQL [root @ www ~] # Mysql-u root-pmysql> use mysql; mysql> update user set password = password ("123456") where user = "root"; mysql> flush privileges;
# Start the MySQL service [root @ www ~] #/Etc/init. d/mysql start