Ubuntu - MySQL Service Startup Failure with Mounted Data-Directory
Resolving a MySQL startup error Job failed to start
, ran as an Ubuntu service systemctl start mysql.service
(or service mysql start
)
configured to have its data
folder on another partition.
After moving to a new PC with a smaller SSD partition and a larger one for data, I configured MySQL to use its data folder on a directory on that partition.
TLDR: The solution to this is a misconfigured partition-folder modes. Make sure all upper directories have 0755
mode.
For more information about possible error logs and configuration, see below.
Configuration and Syslog Error⌗
Even with the correct configuration and data-folder ownership, above issue occurred.
Checking the /etc/mysql/mysql.conf.d/mysqld.cnf
config file:
datadir = /data/mysql_data
And the folder’s ownership is properly set to:
$ stat -c "%U %G" mysql_data/
mysql mysql
=> Seems good
Syslog Error⌗
Looking at /var/log/syslog
I found:
mysqld: Can't change dir to '/data/mysql_data/' (Errcode: 13 - Permission denied)
...
... 0 [Warning] Can't create test file /data/mysql_data/myhost.lower-test
Workaround⌗
In many places there are suggestions resolving this issue with tweaking apparmor
,
I tried that for quite a while but without success. And since I had to move along I just started MySQL inside as a docker container:
$ docker run --rm -p 3306:3306 --name=mysql57 -v /data/mysql_config/mysql.cnf:/etc/my.cnf -v /data/mysql_data:/var/lib/mysql -d mysql/mysql-server:5.7
which works fine. Just when connecting to it, the connection protocol has to be set to TCP:
$ mysql -u admin -ppwd --protocol=tcp ...
Solution⌗
After a while I came across namei
and finally saw that the parent folder required a chmod
to make it readable/executable.
From the man page: namei - follow a pathname until a terminal point is found
and prints the mode and ownership of the recursive directories.
$ namei -l /data/mysql_data
f: /data/mysql_data/
drwxr-xr-x root root /
drwx------ tokosh tokosh data
drwxr-xr-x mysql mysql mysql_data
And after changing the data
folder to chmod 0755 /data
, the MySQL service was finally functional. ε-(´・`) フ