This is about resetting the MySQL 5.7 root password in Ubuntu 16.04 LTS
You probably tried something like this:
sudo service mysql stop mysqld_safe --skip-grant-tables &
And then got something like this (stangely, exists is misspelled in the output):
[1] 5599 2018-03-02T21:36:41.292413Z mysqld_safe Logging to syslog. 2018-03-02T21:36:41.294798Z mysqld_safe Logging to '/var/log/mysql/error.log'. 2018-03-02T21:36:41.296902Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
Then you tried to find the socket (takes a while):
sudo find / -type s
And /var/run/mysqld does not exist.
So you start mysql again and search and now it does exist!
sudo service mysql start sudo find / -type s [output:] /run/mysqld/mysqld.sock /run/dbus/system_bus_socket /run/acpid.socket /run/snapd-snap.socket ...
My guess is that mysql_safe can’t create the directory (which appears to be dynamically created when mysql starts). Solution:
sudo mkdir /var/run/mysqld sudo chown mysql:mysql /var/run/mysqld
Now run:
sudo service mysql stop mysqld_safe --skip-grant-tables & mysql -uroot mysql
When you get to the mysql prompt (don’t forget to change your pw before copy/pasting!!!):
UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%'; exit;
then
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown sudo service mysql start
OTHER SOLUTION (means restarting MySQL a couple times!):
Note: in MySQL 5.7 you may find that my.cnf actually references config files elsewhere:
!includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/
So in my case:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Under [mysqld] add:
skip-grant-tables
Close the file and restart mysql, then…
sudo service mysql restart sudo mysql -uroot mysql (use query above...)
Edit mysqld.conf again, remove the line, then restart MySQL
sudo service mysql restart
Good luck!