How to reset MySQL phpMyAdmin Root Password On Ubuntu 16.04 / 17.10 And 18.04 LTS

Setting MySQL Root Password

To reset MySQL root password, logon to the Ubuntu server and run the commands below to stop MySQL database service

sudo /etc/init.d/mysql stop

Then run the commands below to create a new mysqld directory

sudo mkdir /var/run/mysqld/

and give mysql user access to it.

sudo chown mysql /var/run/mysqld/

After that, run the commands below to start MySQL in safe mode by bypassing the standard authentication process…

sudo mysqld_safe --skip-grant-tables &

You should see something like this… you may have to press the Enter key

richard@ubuntu1710:~$ 2017-12-25T16:49:30.551520Z mysqld_safe Logging to syslog. 2017-12-25T16:49:30.554646Z mysqld_safe Logging to ‘/var/log/mysql/error.log’. 2017-12-25T16:49:30.578079Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 2017-12-25T16:49:32.568746Z mysqld_safe mysqld from pid file /var/run/mysqld/ ended [1]+ Done sudo mysqld_safe --skip-grant-tables

Next, run the commands below to logon to the database server with the root account without typing a password… you’re given root access to the database without entering the password…

sudo mysql -u root

Once logged into the database, run the SQL command statement below to use the default mysql database… this database holds the settings for root user and other server settings…

use mysql;

The output should look like the one below:

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

Finally, run the SQL statement below to change the root password

update user set authentication_string=PASSWORD("New_Passwore_Here") where User='root';

Save the change by running the commands below

flush privileges; exit;

Finally, stop MySQL safe_mode and start MySQL default service

sudo /etc/init.d/mysql stop sudo /etc/init.d/mysql start

If you did everything as described above, you should be able to log back onto MySQL database using the root new password.

sudo mysql -u root -p