In this tutorial we will cover how to reset the root password of MySQL and MariaDB on CentOS 7 / RHEL 7
Step 1 – Checking the version of Database Server
[[email protected] ~]# mysql --version mysql Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1
Step 2 — Stopping the Database Server
[[email protected] ~]# sudo systemctl stop mariadb # FOR MARIADB [[email protected] ~]# sudo systemctl stop mysql # FOR MYSQL
Step 3 — Resetting the Root Password
– Start manually with skip grants tables and skip networking in background
[[email protected] ~]# sudo mysqld_safe --skip-grant-tables --skip-networking &
– Log into mysql
[[email protected] ~]# mysql -u root Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
– Reset the root password using the following command
MariaDB [(none)]> update mysql.user set password=password('MyNewPass') where user='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit
– Stop mysqld_safe Safely
[[email protected] ~]# mysqladmin shutdown
– Start the Database Server
[[email protected] ~]# systemctl start mariadb # FOR MARIADB [[email protected] ~]# systemctl start mysql # FOR MYSQL
We hope this tutorial was enough Helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!