centos7 xtrabackup mysql 基本测试(4)---虚拟机环境 mysql 修改datadir(有问题)

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

https://dev.mysql.com/doc/refman/8.4/en/selinux-file-context.html

https://developer.aliyun.com/article/1238771

创建目录

c 复制代码
sudo mkdir -p /opt/datadir/

首先,关闭MySQL服务:

c 复制代码
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

c 复制代码
# 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=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

保存并关闭文件。此时,需要递归更改新目录的权限,以确保MySQL能够访问其中的数据:

c 复制代码
sudo chown -R mysql:mysql /opt/datadir/mysql
sudo chmod 750 /opt/datadir/mysql

最后,重新启动MySQL服务:

mysql>show variables like '%dir%';

如果启动失败, 使用setenforce 0命令,然后再启动一次试试

c 复制代码
show variables like '%dir';

selinux 与 mysql

semanage

ping www.baidu.com

检查并修改/etc/resolv.conf文件,确保DNS服务器地址正确。

nameserver 8.8.8.8

nameserver 8.8.4.4

CentOS7安装时使用"基础服务器"选项安装, 后发现没有semanage命令.

使用yum查询选项搜索

[root@localhost ~]# yum provides semanage

按照搜索结果安装对应包即可解决

[root@localhost ~]# yum install -y policycoreutils-python

c 复制代码
ping www.baidu.com
yum provides semanage
/usr/sbin/semanage
yum install -y policycoreutils-python-2.5-34.el7.x86_64
semanage 
semanage fcontext -l|grep mysqld_db_t

ls /opt/datadir/mysql/
ls
semanage fcontext -a -t mysqld_db_t "/opt/datadir/mysql(/.*)?"
restorecon -Rv /opt/datadir/mysql
semanage fcontext -l|grep mysqld_db_t

sudo systemctl status mysqld

mysql -u etc -p

show variables like '%dir';

c 复制代码
+---------------------------+----------------------------+
| Variable_name             | Value                      |
+---------------------------+----------------------------+
| basedir                   | /usr/                      |
| character_sets_dir        | /usr/share/mysql/charsets/ |
| datadir                   | /opt/datadir/mysql/        |
| innodb_data_home_dir      |                            |
| innodb_log_group_home_dir | ./                         |
| innodb_tmpdir             |                            |
| lc_messages_dir           | /usr/share/mysql/          |
| plugin_dir                | /usr/lib64/mysql/plugin/   |
| slave_load_tmpdir         | /tmp                       |
| tmpdir                    | /tmp                       |
+---------------------------+----------------------------+
10 rows in set (0.00 sec)
相关推荐
前端白袍9 分钟前
C语言:C语言实现对MySQL数据库表增删改查功能
c语言·数据库·mysql
冰红茶兑滴水1 小时前
MySQL 内置函数
数据库·mysql
ThisIsClark1 小时前
【后端面试总结】MySQL面试总结
mysql·面试·职场和发展
ThisIsClark2 小时前
【后端面试总结】MySQL索引
mysql·面试·职场和发展
代码中の快捷键3 小时前
MySQL数据库存储引擎的数据结构
数据结构·数据库·mysql
好记忆不如烂笔头abc3 小时前
logminer挖掘日志归档查找问题
数据库·sql·mysql
xnuscd12 小时前
Milvus概念
数据库·学习·mysql
云边的快乐猫13 小时前
navicat远程连接虚拟机centos系统的mysql
linux·mysql·centos·虚拟机·navicat
漫天转悠13 小时前
MySQL 七种JOIN连接详解
数据库·mysql
尘浮生13 小时前
Java项目实战II基于Java+Spring Boot+MySQL的智能停车计费系统(开发文档+数据库+源码)
java·开发语言·数据库·spring boot·mysql·微信小程序·maven