CentOS modify MariaDB database file storage path

Time:2021-10-28

Modify MariaDB database file storage path

mysqlIt is also a similar configuration.
MariaDBThe default data storage directory is/var/lib/mysql, ready to change to/data/mysql

Out of Service

systemctl stop mariadb

data migration

mv /var/lib/mysql /data/mysql

Modify configuration

vim /etc/my.cnf

#Add in [client server]
socket=/data/mysql/mysql.sock

#Add in [mysqld], the end must be/
datadir=/data/mysql/

Full configuration

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
socket=/data/mysql/mysql.sock

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[mysqld]
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character_set_server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake=true
datadir=/data/mysql/

Note: the five lines above dataDir set the default character set to utf8mb4, otherwise Emoji expressions cannot be stored correctly.

verification

#Login
mysql -uroot -p

#Inquiry
show global variables like "%datadir%";

#Results
MariaDB [(none)]> show global variables like "%datadir%";
+---------------+--------------+
| Variable_name | Value        |
+---------------+--------------+
| datadir       | /data/mysql/ |
+---------------+--------------+
1 row in set (0.00 sec)