Method to reset the mysql server root password in ubuntu
- 2020-05-14 05:03:20
- OfStack
First stop mysql service:
Then create a new mysql service using the ignore password authentication mode:
Return PID and other startup information after successful startup
Connect to mysql system library:
After connecting to the mysql library, directly change the password of the root account to the new password 'mynewpasswd':
Abort the mysql service process (see screen information for PID 3591 when starting the service) :
Start mysql service normally and login mysql server with new password successfully:
root@webserver:/home/webmaster# service mysql stop
Then create a new mysql service using the ignore password authentication mode:
root@webserver:/home/webmaster# mysqld --user=mysql --skip-grant-tables --skip-networking &
Return PID and other startup information after successful startup
[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:
root@webserver:/home/webmaster# mysql -u root mysql
After connecting to the mysql library, directly change the password of the root account to the new password 'mynewpasswd':
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 (see screen information for PID 3591 when starting the service) :
root@webserver:/home/webmaster# kill 3591
Start mysql service normally and login mysql server with new password successfully:
root@webserver:/home/webmaster#service mysql start
root@webserver:/home/webmaster#mysql -u root -pmynewpasswd