The solution to forget the root password of mysql under linux

1. First make sure that the server is in a secure state, that is, no one can arbitrarily connect to the MySQL database.
Because during the period of resetting the root password of MySQL, the MySQL database is completely in a
state , and other users can also log in and modify MySQL information arbitrarily. The quasi-safe state of the server can be achieved by closing the
external and stopping Apache and all user processes.
The safest state is to operate on the console of the server and unplug the network cable.
2. Modify MySQL login settings:
# vi /etc/my.cnf
Add a sentence to the [mysqld] section: skip-grant-tables
For example:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/ mysql/mysql.sock
skip-grant-tables
save and exit vi.
3. Restart mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
4. Log in and change 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
You 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.将MySQL的登录设置修改回来
# vi /etc/my.cnf
deletes the skip-grant-tables just added to the [mysqld] segment,
saves
6. Restart mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326685512&siteId=291194637