Once I created a raid, mounted it as a disk system partition and transferred the MySQL directory directly to it, but in this case there were drawbacks, the lost+found directory could appear, it could not be used for other data, etc., after that I began to transfer the MySQL directory not directly to the partition, but created a directory on it and transferred it to it.
See my article:
Moving the MySQL data directory to a new location
Suppose you created a raid and mounted it in the /srv/raid10/ directory, at the time of this writing, I created a level 10 raid from 10 SSDs for a highly loaded database.
Create a directory for MySQL data:
mkdir /srv/raid10/mysql/
Let’s specify the user and group on behalf of which the MySQL server is running:
chown mysql:mysql /srv/raid10/mysql/ -R
chmod 755 /srv/raid10/mysql
You can also do this:
chown --reference=/var/lib/mysql /srv/raid10/mysql
chmod --reference=/var/lib/mysql /srv/raid10/mysql
Let’s open the MySQL server configuration file in a text editor, for example:
nano /etc/mysql/mysql.conf.d/mysqld.cnf
Let’s change the path to the files to a new location:
[mysqld]
datadir=/srv/raid10/mysql
I also specified in the /etc/mysql/mysql.conf.d/mysqld_safe_syslog.cnf file:
[mysqld_safe]
datadir=/srv/raid10/mysql
If apparmor is used, then in its configuration it is also necessary to specify a new directory, open the apparmor configuration, for example:
nano /etc/apparmor.d/usr.sbin.mysqld
I found lines:
# Allow data dir access
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
And I added after them:
/srv/raid10/mysql/ r,
/srv/raid10/mysql/** rwk,
To apply the changes, restart apparmor:
/etc/init.d/apparmor reload
systemctl restart apparmor
Now you can stop the MySQL server:
systemctl stop mysql
We copy the data to a new location:
rsync -av /var/lib/mysql /srv/raid10/mysql
We check:
ls -l /srv/raid10/mysql/
We start the MySQL server:
systemctl start mysql
systemctl status mysql
Let’s reboot the server to make sure that the raid array was mounted at system startup and the MySQL server starts successfully:
reboot