默认情况下MariaDB的存储为/var/lib/mysql/,现在因为某种原因需要改为/media/data/mysql。
1、首先停掉MariaDB和httpd的守护进程:
# systemctl stop mariadb.service
# systemctl stop httpd.service
2、将/var/lib/mysql/复制到/media/data/下:
# cp -avp /var/lib/mysql/ /media/data/
3、修改MariaDB的配置文件:
检查MariaDB的配置文件 :
# rpm -qc mariadb-server
/etc/logrotate.d/mariadb
/etc/my.cnf.d/server.cnf
/var/log/mariadb/mariadb.log
可得出要修改的配置文件为/etc/my.cnf.d/server.cnf,修改之:
先进行备份,以防万一:
# cp -p /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.backup
修改MariaDB服务器,注释掉原来的datadir和socket,并重新添加:
# vim /etc/my.cnf.d/server.cnf
[mysqld]
#datadir=/var/lib/mysql
datadir=/media/data/mysql
#socket=/var/lib/mysql/mysql.sock
socket=/media/data/mysql/mysql.sock
修改MariaDB客户端的配置文件 (若不修改此项,在使用mysql连接服务器时会提示找不到socket文件):
# cp -p /etc/my.cnf.d/client.cnf /etc/my.cnf.d/client.cnf.backup
# vim /etc/my.cnf.d/client.cnf
[client]
socket=/media/data/mysql/mysql.sock
4、修改php连接MariaDB的socket位置:
# vim /etc/php.ini
mysql.default_socket = /media/data/mysql/mysql.sock
#此项一般为空,现在需要手机指定上,不然php不能和MariaDB通信
5、启动MariaDB和httpd服务:
# systemctl start mariadb.service
# systemctl start httpd.service
此时,修改完毕。