How To Reset The MySQL Root Password In Linux (Ubuntu 18.04)
- Need sudo access on Linux system.
Step 1 : Stop Currently Running MySQL Service
First thing that we need to stop running MySQL service
sudo service mysql stop
Step 2: Creating The Required Directory
create a /var/run/mysqld directory to be used by MySQL process to store and access socket file
sudo mkdir -p /var/run/mysqld sudo chown mysql:mysql /var/run/mysqld
Step 3: Manually Start MySQL Service
In this method, you stop the server and start it by specifying –skip-grant-tables, which will not load the grant tables. You can connect to the server as root without a password and set the password.
Since the server runs without grants, it is possible for users from other networks to connect to the server. So –skip-grant-tables automatically enables –skip-networking, which does not allow remote connections
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &  22917
Step 4: Take MySQL Databases Access Without Password
Login to MySQL server without Root Password
mysql -u root
Step 5: Reset The MySQL Root User Password
After login we got the MySQL console. Using following MySQL commands we are going to update the MySQL root password.
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 authentication_string=PASSWORD("********") WHERE User='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> UPDATE user SET plugin="mysql_native_password" WHERE User='root'; Query OK, 0 rows affected (0.01 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql> quit Bye
Step 6: Kill The MySQL Service
After updating root password we need to kill that MySQL process (which is started by us).
sudo pkill mysqld
Step 7: Start MySQL Service
Start the MySQL service using following command
sudo service mysql start
Step 8: Login With New Password
Login to MySQL server with new password of root user.
mysql -uroot -p******** mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.27-0ubuntu0.18.04.1 (Ubuntu) Copyright (c) 2000, 2019, 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>
There’s no silver bullet solution with cyber security, a layered defence is the only viable defence.