What if you forget your MySQL password? MySQL Resets root password methods
- 2021-01-22 05:32:40
- OfStack
MySQL Sometimes forgetting the root password is a sad thing. Password reset methods under Windows and Linux are provided here.
Windows:
1. Log in as the system administrator.
2. Open cmd-----net start to see if mysql is on. Stop net stop mysql on startup.
3. My mysql is installed under d:\usr\local\mysql4\bin.
4. Start mysql by skipping permission checks.
d:\usr\local\mysql\bin\mysqld-nt --skip-grant-tables
5. Open cmd again. d:\usr\local\mysql4\bin :\usr\local\mysql4\bin:
d:\usr\local\mysql\bin\mysqladmin -u root flush-privileges password "newpassword"
d:\usr\ mysql\bin\mysqladmin -u root -p shutdown :\usr\local\mysql\bin\mysqladmin -u root -p shutdown.
6. In cmd, net, start, mysql
7. We're done.
Linux:
MySQL root password recovery method 1
If you forget the MySQL root password, you can reset it using the following methods:
1.KILL eliminates the MySQL process in the system;
killall -TERM MySQLd
2. Start MySQL without checking permissions with the following command;
safe_MySQLd --skip-grant-tables
&
3. Then log into MySQL with empty password as root user;
MySQL -u root
4. Change the password of root user;
MySQL
>
update user set password=PASSWORD(' New password ') where ES1010EN ='root';
MySQL
>
flush privileges;
MySQL
>
quit
Restarting MySQL will enable you to log in with your new password.
MySQLroot password recovery method 2
It is possible that your system does not have safe_MySQLd program (for example, I am using ubuntu operating system, apt-get installed MySQL), the following method can restore
1. Stop MySQLd;
sudo /etc/init.d/MySQL stop
(You may have other options, but just stop MySQLd.)
2. Start MySQL without checking permissions with the following command:
MySQLd --skip-grant-tables
&
3. Then log into MySQL with empty password as root user;
MySQL -u root
4. Change password of root user;
MySQL
>
update MySQL.user set password=PASSWORD('newpassword') where User='root';
MySQL
>
flush privileges;
MySQL
>
quit
Restart MySQL
/etc/init.d/MySQL restart
You can log in with your new password newpassword.