ssuhat's avatar

Homestead ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

I've recently upgrade my homestead to latest release (Ubuntu 16.04) and reinitialize all homestead.yaml, etc.

I've put: mariadb: true inside Homestead.yaml. Everything installed perfectly and running normally. But after sometime mysql will stop by itself.

Error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

I've tried sudo services mysql reload. its working back to normal but start shutting down after few minutes.

Before upgrading everything is working perfectly.

Any suggestion? I've tried re-provision still no hope.

0 likes
5 replies
ssuhat's avatar
ssuhat
OP
Best Answer
Level 1

apparmor was the culprit. Despite the contents of /etc/apparmor.d/usr.sbin.mysqld being nothing but comments and claiming that it was there so that apparmor wouldn't choke on MariaDB, that's exactly what was happening.

AppArmor and MySQL on an Oracle blog provided what I needed to figure out what was going on.

sudo aa-status shows you what apparmor is doing; what actually has an enforced policy, versus what's just set to complain.

sudo apt-get install apparmor-utils adds a few commands that make the apparmor profiles easier to deal with, such as...

sudo aa-complain /usr/sbin/mysqld turns the profile from "enforce" to complain. (aa-enforce turns it back.)

Once that's done, sudo service apparmor reload restarts apparmor, and voila... sudo /etc/init.d/mysql start works, and the server stays up.

Reference: https://askubuntu.com/questions/750604/why-does-mariadb-keep-dying-how-do-i-stop-it

3 likes
eclev91's avatar

I'm having what seems to be the same issue, but your solution gets me the following error:

ERROR: /etc/apparmor.d/usr.sbin.mysqld contains no profile

Anyone have thoughts on this?

2 likes

Please or to participate in this conversation.