how to start mariaDB on boot after external drive is mounted

Noel Swanson :

I am using a raspberry pi 3 with OSMC as the operating system along with Debian Stretch and nginx, and installed manually mariaDB 10.2 following some instructions I found somewhere a while back.

I have changed the datadir for mariadb to /media/USBHDD2/shared/mysql

When I boot, or reboot, the pi, mariaDB fails to start. Before, when I had the default datadir = /var/lib/mysql it was all fine. If I change it back it is fine.

However, if I login to the console I can successfully start it by using

service mysql start

Note that I am using 'service' rather than 'systemctl' - the latter does not work. The files mariadb.service and mysql.service do not exist anywhere.

In /etc/init.d I find two files: mysql and myswql which seem to be identical. If I remove the myswql from the directory mariadb won't start at all. I have tried editing these by putting, for example, a sleep 15 at the beginning, but to no avail. I have read all sorts of solutions about trying to test if the USBHDD2 is mounted, eg using

while ! test -f /media/USBHDD2/shared/test.txt
do
  sleep 1
done

which I tried in the /etc/init.d/mysql and myswql files, and also in rc.local before calling for the start of mysql. But that doesn't work either.

I also renamed the links in rc?.d to S99mysql so is starts after everything else, still no joy.

I have spent two full days on this to no avail. What do I need to do to get this working so that mysql starts on boot?

Files system is ntfs

output from ls -la //media/USBHDD2/shared/mysql is as follows:

total 176481
drwxrwxrwx 1 root root     4096 Mar 27 11:41 .
drwxrwxrwx 1 root root     4096 Mar 27 13:06 ..
-rwxrwxrwx 1 root root    16384 Mar 27 11:41 aria_log.00000001
-rwxrwxrwx 1 root root       52 Mar 27 11:41 aria_log_control
-rwxrwxrwx 1 root root        0 Nov  3  2016 debian-10.1.flag
-rwxrwxrwx 1 root root    12697 Mar 27 11:41 ib_buffer_pool
-rwxrwxrwx 1 root root 50331648 Mar 27 11:41 ib_logfile0
-rwxrwxrwx 1 root root 50331648 Mar 26 22:02 ib_logfile1
-rwxrwxrwx 1 root root 79691776 Mar 27 11:41 ibdata1
drwxrwxrwx 1 root root    32768 Mar 25 18:37 montegov_admin
-rwxrwxrwx 1 root root        0 Nov  3  2016 multi-master.info
drwxrwxrwx 1 root root    20480 Sep  3  2019 mysql
drwxrwxrwx 1 root root        0 Sep  3  2019 performance_schema
drwxrwxrwx 1 root root    86016 Mar 25 20:06 rentmaxpro_wp187
drwxrwxrwx 1 root root        0 Sep  3  2019 test
drwxrwxrwx 1 root root    32768 Nov  3  2016 trustedhomerenta_admin
drwxrwxrwx 1 root root    32768 Nov  3  2016 trustedhomerenta_demo
drwxrwxrwx 1 root root    40960 Mar 25 21:05 trustedhomerenta_meta
drwxrwxrwx 1 root root    36864 Mar 25 21:25 trustedhomerenta_montego
drwxrwxrwx 1 root root    36864 Mar 26 20:37 trustedhomerenta_testmontego
Noel Swanson :

The problem is that the external drive is configured as ntfs.

Mysql requires the files and directory to be owned by mysql:mysql but since the ntfs does not have the same system of owners and groups as linux, the linux mount process asigns its own owner and group to the filestructure when mounting the drive. By defualt this ends up being root:root so mysql cannot use them.

ntfs does not allow CHOWN to work, so there is no way to change the ownership away from root.

One solution is to backup all the files, repartition as EXT4, and then restore all the files.

The solution I finally used was to specify mysql as the owner and group at the time that the drive is being mounted. Thus my /etc/fstab file was changed to:

ID=C2CA68D9CA68CB6D /media/USBHDD2 ntfs users,exec,uid=mysql,gid=mysql 0 2

and now mysql starts properly at boot.

phew ;-)

Thanks @danblack for getting me thinking in the right direction

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=379484&siteId=1