centos7 xtrabackup mysql 基本测试(4)—虚拟机环境 mysql 修改datadir
参考
centos更改mysql数据库目录
https://blog.csdn.net/sinat_33151213/article/details/125079593
https://blog.csdn.net/jx_ZhangZhaoxuan/article/details/129139499
创建目录
sudo mkdir -p /opt/datadir/
首先,关闭MySQL服务:
sudo systemctl stop mysqld
sudo systemctl status mysqld
然后,复制原始datadir目录,作为新的目录:
sudo cp -rp /var/lib/mysql /opt/datadir/
sudo ls /opt/datadir/mysql/
接下来,修改 MySQL配置文件my.cnf:
sudo cp /etc/my.cnf /etc/org_my.cnf
sudo vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/opt/datadir/mysql/
socket=/opt/datadir/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
保存并关闭文件。此时,需要递归更改新目录的权限,以确保MySQL能够访问其中的数据:
sudo chown -R mysql:mysql /opt/datadir/mysql
sudo chmod 750 /opt/datadir/mysql
最后,重新启动MySQL服务:
mysql>show variables like ‘%dir%’;
如果启动失败, 使用setenforce 0命令,然后再启动一次试试
show variables like '%dir';