First stop the MySQL service:
Copy Code code as follows:
root@webserver:/home/webmaster# service MySQL Stop
Then recreate a MySQL service using the Ignore Password Authentication mode:
Copy Code code as follows:
root@webserver:/home/webmaster# mysqld--user=mysql--skip-grant-tables--skip-networking &
Return PID and other startup information after successful startup
Copy Code code as follows:
[1] 3591
root@webserver:/home/webmaster# 121005 2:59:27 [note] Plugin ' federated ' is disabled.
121005 2:59:27 innodb:the InnoDB memory heap is disabled
121005 2:59:27 innodb:mutexes and rw_locks use GCC atomic builtins
121005 2:59:27 innodb:compressed tables use zlib 1.2.3.4
121005 2:59:27 innodb:initializing buffer pool, size = 128.0M
121005 2:59:27 innodb:completed initialization of buffer pool
121005 2:59:27 innodb:highest Supported file format is barracuda.
121005 2:59:27 innodb:waiting for the background threads to start
121005 2:59:28 innodb:1.1.8 started; Log sequence Number 1595685
121005 2:59:28 [note] Mysqld:ready for connections.
Version: ' 5.5.24-0ubuntu0.12.04.1 ' socket: '/var/run/mysqld/mysqld.sock ' port:0 (Ubuntu)
Connect to MySQL System library:
Copy Code code as follows:
root@webserver:/home/webmaster# mysql-u Root MySQL
After connecting to the MySQL library, directly modify the root account password for the new password ' mynewpasswd ':
Copy Code code as follows:
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
mysql> Update user Set Password=password (' mynewpasswd ') where user= ' root ';
Query OK, 3 Rows Affected (0.00 sec)
Rows Matched:3 Changed:3 warnings:0
mysql> FLUSH privileges;
Mysql> quit;
Bye
Abort the MySQL service process (PID 3591 See screen information before starting the service):
Copy Code code as follows:
root@webserver:/home/webmaster# Kill 3591
Start the MySQL service normally and log on to the MySQL server successfully with the new password:
Copy Code code as follows:
Root@webserver:/home/webmaster#service MySQL Start
Root@webserver:/home/webmaster#mysql-u root-pmynewpasswd