Long time Login vps, then mysql password forgot .... So, Baidu's, record a bit
1. First confirm that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily. Because the MySQL database is completely out of password-protected state during the reset of the root password of MySQL, other users can log in and modify the MySQL information arbitrarily. Own VPS also no one knows, should be safe state.
2. Modify the MySQL login settings:
#vim/etc/my.conf Eg:
[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Skip-grant-tables
Save and exit Vim
3. Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]
4.
4. Log in and modify the root password of MySQL
#/usr/bin/mysql
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3 to server version:3.23.56
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.
mysql> use MySQL;
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a
Database changed
mysql> UPDATE user SET Password = Password (' New-password ') WHERE user = ' root ';
Query OK, 0 rows Affected (0.00 sec)
Rows matched:2 changed:0 warnings:0
mysql> flush Privileges;
Query OK, 0 rows affected (0.01 sec)
Mysql> quit
Bye
5. Change MySQL login settings back
# VI/ETC/MY.CNF
Delete the skip-grant-tables you just added in the paragraph [mysqld]
Save and Exit VI.
6. Restart Mysqld
#/etc/init.d/mysqld Restart
stopping MySQL: [OK]
Starting MySQL: [OK]
MySQL forgot password under Linux