I have a Wordpress website that used to work fine, but recently I received the message “Error establishing a database connection” when trying to navigate to it. Upon researching online, I realized it may be related to changing my db password.

So I am following instructions on resetting the Mysql pw from here - https://www.digitalocean.com/community/tutorials/how-to-reset-your-mysql-or-mariadb-root-password.


sudo systemctl stop mysql

sudo mysqld_safe --skip-grant-tables --skip-networking &


2019-08-25T15:23:22.702830Z mysqld_safe Logging to syslog.
2019-08-25T15:23:22.707805Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2019-08-25T15:23:22.712056Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

I then do:

mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld

and then run
sudo mysqld_safe --skip-grant-tables --skip-networking &


2019-08-25T15:33:49.404761Z mysqld_safe Logging to syslog.
2019-08-25T15:33:49.411891Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2019-08-25T15:33:49.443922Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2019-08-25T15:33:49.992471Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

From here, I do mysql -u root, and see this


ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Troubleshooting done so far

To troubleshoot, I followed the suggestions from this post to find the sock file. I tried to do by by

sudo find / -type s to find the mysql.sock file, but do not find it in the list.



I tried to restart the server by sudo service mysql start but got this output

Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

The output for systemctl status mysql.service is

 mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Sun 2019-08-25 15:41:53 UTC; 27s ago
  Process: 16974 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 16966 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCE
 Main PID: 16974 (code=exited, status=1/FAILURE);         : 16975 (mysql-systemd-s)
    Tasks: 2
   Memory: 5.1M
      CPU: 331ms
   CGroup: /system.slice/mysql.service
             ├─16975 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─17042 sleep 1

Aug 25 15:41:53 keshinpoint systemd[1]: Starting MySQL Community Server...
Aug 25 15:41:53 keshinpoint systemd[1]: mysql.service: Main process exited, code=exited, status=1/F

Feels like a rabbit hole here. Can someone please help me with this? I would be grateful for any guidance offered, as Ive tried answers from multiple stackoverflow posts.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

1 answer


It looks like that for some reason MySQL is not starting when you run the mysqld_safe command, that is why you get the Can't connect to local MySQL error when you try to connect.

I would recommend first checking your MySQL error log:


There you should find more information on why MySQL is not starting.

If you are not sure how to proceed even after seeing the errors, you could share the error here so I could advice you further.


Submit an Answer