How to reset MySQL root password on Linux


You forgot or you unknow your root MYSQL password! How to reset MariaDb root password on Linux?

Step 1: stop mysqld

service mysqld stop

Result:

[root@tutorialspots ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]

Step 2:

sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -u root
use mysql;
update user set password=PASSWORD("new-password") where User='root';
flush privileges;
exit;

Result:

[root@tutorialspots ~]# sudo mysqld_safe --skip-grant-tables --skip-networking &
[1] 14033
[root@tutorialspots ~]# 190118 07:30:14 mysqld_safe Logging to '/var/log/mysqld.log'.
190118 07:30:14 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.36 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

Step 3: stop and start Mariadb service

[root@tutorialspots ~]# service mysqld stop
190118 07:33:19 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
[1]+  Done                    sudo mysqld_safe --skip-grant-tables --skip-networking
[root@tutorialspots ~]# service mysql start
Starting mysqld:                                           [  OK  ]

Note: You can’t use command service mysqld restart

Leave a Reply