Ubuntu – Can’t start thesql on Ubuntu 18.04.1 LTS. ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/thesqld/thesqld.sock’ (2)

18.04Apache2MySQLWordpress

If anyone could lend me some assistance, I'll be very grateful. I'm a novice at back-end, just a humble designer/front end person.

Ok – from the beginning…: I have a desktop Ubuntu 18.04.1 LTS Ubuntu and have been building a local WordPress for a few months. I kept noting I was running out of space on my box, realized it was Flatpak [curse you Flatpak!!!] was adding gigs of space daily for no good reason. So I bit the bullet and removed it.

Of course it killed my WP site. After many torturous hours, I finally reinstalled Apache2 and MySql. I recall changing a password or two along the way, so I think that could be part of the problem…Anyhow, I did get back into my site and immediately backed it up using a plugin [updraftplus] to a remote server. [so at worst I will migrate to a live server but would prefer to make this work again.]

But today, I booted back up and checked my local site and it says 'Error establishing a database connection' on both WP site/login pages. So I checked apache2 – working. Mysql is not.
When I run 'service mysql status' I get this:

mysql.service - MySQL Community Server

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)

Active: failed (Result: exit-code) since Sat 2019-02-02 12:19:06 EST; 48min ago

Process: 3317 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)

Process: 3308 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)

Feb 02 12:19:06 kjj-desktop systemd[1]: mysql.service: Service hold-off time over, scheduling restart.

Feb 02 12:19:06 kjj-desktop systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.

Feb 02 12:19:06 kjj-desktop systemd[1]: Stopped MySQL Community Server.

Feb 02 12:19:06 kjj-desktop systemd[1]: mysql.service: Start request repeated too quickly.

Feb 02 12:19:06 kjj-desktop systemd[1]: mysql.service: Failed with result 'exit-code'.

Feb 02 12:19:06 kjj-desktop systemd[1]: Failed to start MySQL Community Server.

I can't find any log folder/files [Damn you Stacer! It killed the apache2 log and I suspect this too!]
Also, when I check the status of Mysql via this cmd 'mysqladmin -u root -p status', I get this:

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

and this is from the syslog:

Feb  2 20:27:37 kjj-desktop systemd[1]: Starting MySQL Community Server...
Feb  2 20:27:37 kjj-desktop kernel: [10290.580203] audit: type=1400 audit(1549157257.767:141): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=15427 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Feb  2 20:27:37 kjj-desktop kernel: [10290.608820] audit: type=1400 audit(1549157257.795:142): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=15429 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=124 ouid=0
Feb  2 20:27:37 kjj-desktop mysqld[15429]: 2019-02-03T01:27:37.975231Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
Feb  2 20:27:37 kjj-desktop mysqld[15429]: 2019-02-03T01:27:37.976433Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.25-0ubuntu0.18.04.2) starting as process 15431 ...
Feb  2 20:27:37 kjj-desktop mysqld[15429]: 2019-02-03T01:27:37.978696Z 0 [ERROR] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory
Feb  2 20:27:37 kjj-desktop mysqld[15429]: 2019-02-03T01:27:37.978727Z 0 [ERROR] Aborting
Feb  2 20:27:37 kjj-desktop mysqld[15429]: 2019-02-03T01:27:37.978771Z 0 [Note] Binlog end
Feb  2 20:27:37 kjj-desktop mysqld[15429]: Initialization of mysqld failed: 0
Feb  2 20:27:37 kjj-desktop mysqld[15429]: 2019-02-03T01:27:37.978842Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
Feb  2 20:27:37 kjj-desktop systemd[1]: mysql.service: Control process exited, code=exited status=1
Feb  2 20:27:37 kjj-desktop systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb  2 20:27:37 kjj-desktop systemd[1]: Failed to start MySQL Community Server.
Feb  2 20:27:38 kjj-desktop systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Feb  2 20:27:38 kjj-desktop systemd[1]: mysql.service: Scheduled restart job, restart counter is at 4.
Feb  2 20:27:38 kjj-desktop systemd[1]: Stopped MySQL Community Server.

So I am tempted to again remove/purge mysql but I bet this will happen again.

Any kind people out there that can help me?! Oh I hope so…running out of options and patience. I didn't sign up for this 🙁

Thanks!

Best Answer

This error occurs due to multiple installations of mysql. Run the command:

ps -A|grep mysql

Kill the process by using:

sudo pkill mysql

and then run command:

ps -A|grep mysqld

Also Kill this process by running:

sudo pkill mysqld

Now you are fully set just run the following commands:

service mysql restart
mysql -u root -p
Related Question