The root password of mysql under linux forgot to solve

  

1. First confirm that the server is in a secure state, that is, no one can arbitrarily connect to the MySQL database. Because the MySQL database is completely out of password protection during the reset of MySQL's root password, other users can log in and modify MySQL information arbitrarily. You can enclose the ports outside of MySQL and stop the Apache and all user processes to achieve the server's quasi-safe state. The safest state is to operate on the server's Console and unplug the network cable. 2. Modify the 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 modify the MySQL root password # /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 &lsquo ;\\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. Modify the MySQL login settings back # vi /etc/my.cnf Delete the skip-grant-tables just added in the [mysqld] section and exit vi. 6. Restart mysqld # /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ]

Copyright © Windows knowledge All Rights Reserved