CentOS下mysql数据库data目录迁移和配置优化
目录迁移
关闭数据库服务
service mysqld stop
复制数据库
mv /var/lib/mysql /data/mysql # 或者使用cp -a复制 # 这两个命令都会带权限到新目录去
修改配置文件 /etc/my.cnf
[mysqld] #datadir=/var/lib/mysql ------原系统默认路径 datadir=/data/mysql ------现有路径 #socket=/var/lib/mysql/mysql.sock ------原socket路径现 socket=/data/mysql/mysql.sock ------现有路径 [mysqld_safe] socket=/data/mysql/mysql.sock -----现有路径 [client] socket=/data/mysql/mysql.sock -----现有路径 [mysql.server] socket=/data/mysql/mysql.sock -----现有路径
重新启动服务
service mysqld start
遇到迁移目录之后无法启动的问题,有可能是selinux搞的鬼,可以设置成Permissive模式
# getenforce Enforcing # setenforce 0 # getenforce Permissive # setenforce 1 设置SELinux 成为enforcing模式 # setenforce 0 设置SELinux 成为permissive模式
或者之间关闭selinux,vi /etc/selinux/config 修改 SELINUX=disabled
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
配置优化
yum安装的mysql默认配置似乎是不能满足要求的,主要修改以下配置
# 批量执行语句包的大小 max_allowed_packet = 16M # innodb缓存,设置为服务器内存的 80%左右 innodb_buffer_pool_size = 2048M # 锁等待超时时间 innodb_lock_wait_timeout = 30 # 0时表示关闭,1时表示打开,2表示只要select 中明确指定SQL_CACHE才缓存 query_cache_type = 0 # 最大连接数 max_connections = 1024 # 下面两个参数一起设定 innodb_flush_log_at_trx_commit = 2 sync_binlog = 1000 # 表不区分大小写 lower_case_table_names = 1
相关推荐
emmm00 2020-11-17
王艺强 2020-11-17
aydh 2020-11-12
世樹 2020-11-11
zry 2020-11-11
URML 2020-11-11
spurity 2020-11-10
yifangs 2020-10-13
Andrea0 2020-09-18
Ida 2020-09-16
ltd00 2020-09-12
tufeiax 2020-09-03
xjd0 2020-09-10
greatboylc 2020-09-10
adsadadaddadasda 2020-09-08
疯狂老司机 2020-09-08
CoderToy 2020-11-16
ribavnu 2020-11-16
bianruifeng 2020-11-16