Reset the MySQL 5.7 root password in Ubuntu 16.04 LTS

This is a bit gnarly. If you have a better method of updating the password without triggering a warning about PASSWORD being deprecated, I’m all ears.

# Stop MySQL
sudo service mysql stop

#############################################
To kill all mysqld process :
----
# killall mysqld mysqld_safe
----
Wait for 10 seconds atleast so that it shut down cleanly.

Now, run this command to check whether still there are some mysqld process remained or not ?
----
# ps aux | grep mysqld
----

If you still able to see more than run this command :
----
killall -9 mysqld mysqld_safe
----
This will kill all mysqld processes.
########################################################

# Make MySQL service directory.
sudo mkdir /var/run/mysqld
# Give MySQL user permission to write to the service directory.
sudo chown mysql: /var/run/mysqld
# Start MySQL manually, without permission checks or networking.
sudo mysqld_safe --skip-grant-tables --skip-networking &

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/mysqld.pid ended


# Log in without a password.
mysql -uroot mysql

Update the password for the root user.

UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
EXIT;
# Turn off MySQL.
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
# Start the MySQL service normally.
sudo service mysql start

source : https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts
Posted on: December 19, 2018, by :