You are not logged in.

#1 2016-12-27 21:39:36

rcrath
Member
Registered: 2014-09-20
Posts: 4

[SOLVED] moving mysql data to a roomier disk

Hi,
I think this is solved, but others were looking for the answer and the other solution did not work for me and at least one other person and the solution I found is not listed anywhere.  Let me know if it is a bad solution!

I wanted to move /var/lib/mysql to a partition with more room on it, but changing the the "datadir" flag in my cnf and setting ProtectHome" to false did not do the trick.  I could start from the command line, but not as a service.

I deleted all the config files, reinstalled mariadb, created a new partition on a usb disk using gparted with the mysql data at the top level, did some renaming, mounted the new partition to /var/lib/mysql, chowned it and restarted the server :

perhaps relevant here is that this is a testing platform, not exposed anywhere beyond the local machine and not remote accessible.

# systemctl stop mysqld
# cp /var/lib/mysql /run/media/USERNAME/USBDISK
# mv /var/lib/mysql /var/lib/mysql.bak
# mkdir /var/lib/mysql
# sudo mount --bind /run/media/USERNAME/USBDISK /var/lib/mysql
# chown -R mysql:mysql /var/lib/mysql
# systemctl start mysqld

Last edited by rcrath (2016-12-28 20:32:47)

Offline

#2 2016-12-27 21:49:15

rcrath
Member
Registered: 2014-09-20
Posts: 4

Re: [SOLVED] moving mysql data to a roomier disk

only remaining issue is to figure out how to set this up in fstab so USBDisk no longer automounts as USB disk and mounts as var/lib/mysql with the proper ownership on startup.  Researching now and will report back if I figure it out, but if anyone can help with this (assuming there are not greater problems with doing the whole operation this way)  I would appreciate it!

Last edited by rcrath (2016-12-28 20:49:30)

Offline

#3 2016-12-28 20:49:00

rcrath
Member
Registered: 2014-09-20
Posts: 4

Re: [SOLVED] moving mysql data to a roomier disk

ok, to make it permanent, refer to

man mount

and search for "bind."
0. stop mysqld:

systemctl stop mysqld

1. turn off automount for the partition you want to use in udisk2 (gnome-disk-util replacement or equivalent) as these do not turn up in fstab and cause the bind statement that we will put in fstab to fail, I think because the udisk automount does not take place until after fstab is processed and we need the partition to be mounted in order to do the bind.

2. add the following lines, edited for your system, to /etc/fstab, substituting your UUID, username, and partition name (for details on this, consult fstab and mount man pages):

UUID=YOURUUIDHERE/run/media/USERNAME/PARTITIONNAME ext4    defaults,noatime 0       0
/run/media/USERNAME/PARTITIONNAME        /var/lib/mysql     none    bind    0 0

3. remount all disks

# mount -a

4. check that /var/lib/mysql contains the mysql data
5. start mysqld

systemctl start mysqld

(or instead of 3-5, test by rebooting)

Last edited by rcrath (2016-12-28 20:52:23)

Offline

Board footer

Powered by FluxBB