What if I forget the root password of MySQL?
We do not set the password for MySQL by default, as follows
Default login for MySQL
[Email protected] ~]# Mysql-uroot
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 1
Server Version:5.1.40-log MySQL Community Server (GPL)
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>quit
Bye
Normally, for security reasons, we should set up a password for MySQL.
[Email protected] ~]# mysqladmin-uroot password ' lamlinux '
Setup is complete, we will login again to enter the password
[Email protected] ~]# Mysql-uroot-plamlinux
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3
Server Version:5.1.40-log MySQL Community Server (GPL)
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>quit
Bye
What if we forget the password and do not log on to MySQL?
Initialize the password , reset one,
Enter configuration file
[Email protected] ~]# VIM/ETC/MY.CNF
Add a sentence under ' Slow query '
skip-grant (Skip Authorization)
: Wq
Restart MySQL
[Email protected] ~]#/etc/init.d/mysqld restart
Shutting down MySQL. success!
Starting MySQL. success!
Initialization complete
Can directly use "mysql" command, do not need to enter the-p password, you can directly into MySQL,
[[email protected] ~]# MySQL
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 1
Server Version:5.1.40-log MySQL Community Server (GPL)
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
Then go to use MySQL library
mysql> Use MySQL
No connection. Trying to reconnect ...
Connection Id:2
Current database: * * * NONE * * *
Database changed
Then go to update a table, that is, change the root user's password
mysql> Update user set Password=password ('lam2linux') where user= ' root ';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect ...
Connection Id:4
Current Database:mysql
Query OK, 3 rows affected (0.01 sec)
Rows Matched:3 Changed:3 warnings:0
From the information we see Query OK, 3 rows affected (0.01 sec) shows that the 3rd line has changed ,
Use the following command to view the change information
Mysql>SELECT * from user where user= ' root ' \g;
Quit MySQL
Mysql>exit
Let's get rid of the "skip-grant" in the MySQL config file.
[Email protected] ~]# VIM/ETC/MY.CNF
Remove Skip-grant
: Wq
Restart MySQL
[Email protected] ~]#/etc/init.d/mysqld restart
Shutting down MySQL. success!
Starting MySQL. success!
log in to MySQL again need to enter a password
[Email protected] ~]# Mysql-uroot-plam2linux
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 2
Server Version:5.1.40-log MySQL Community Server (GPL)
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
At this point, after the password has been modified and successfully signed in
MySQL root password forgotten after reset method