centos7中mysql更改資料目錄
一、配置mysql
首先啟動mysql
service mysqld start
設定密碼及安全規則
mysql_secure_installation
這一步驟我只修改了密碼,其它安全規則根據需求修改
修改配置檔案(這裡我修改的為/home目錄下)
datadir=/home/mysql
socket=/home/mysql/mysql.sock
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
character_set_server=utf8
max_allowed_packet = 512M
innodb_log_file_size = 512M
federated
event_scheduler = 1
#
# 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=/home/mysql
socket=/home/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid12345678910111213141516171819202122232425262728293031323334353637
將原目錄下的所有檔案copy到 /home下面
cp -rp /var/lib/mysql /home/
這裡注意需要拷貝所有的檔案包括相對應的許可權
在做一下軟連結,否則會出現啟動不了的情況
ln -s /home/mysql/mysql.sock /var/lib/mysql/mysql.sock
最後重啟一下mysql
service mysqld restart
二、注意情況
在這裡可能會出現無法啟動的情況,還要配置一下selinux,然後重啟機器
vi /etc/selinux/config
將selinux配置為disabled,當然,有其它需求的可以自己配置規則
重啟服務後再啟動mysql就可以啦~