个人觉得最好的方式:

mysql安装完毕通过mysql_install_db命令直接指定对应的存储目录

mysql_install_db --user=mysql --datadir=/data/mysql

同时修改my.cnf下datadir对应路径

系统:

CentOS 6.7 x86_64

安装:

rpm -ivh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

yum -y install mysql mysql-server

查询:

rpm -qa|grep mysql

mysql-community-release-el6-5.noarch

mysql-community-libs-compat-5.6.29-2.el6.x86_64

mysql-community-libs-5.6.29-2.el6.x86_64

mysql-community-client-5.6.29-2.el6.x86_64

mysql-community-server-5.6.29-2.el6.x86_64

mysql-community-common-5.6.29-2.el6.x86_64

启动MySQL:

chkconfig mysqld on

service mysqld start

mysql的默认存储路径路径为/var/lib/mysql,现修改后为/data/mysql

关闭服务

service mysqld stop

复制mysql数据文件到新的目录

mkdir /data

cp -rap /var/lib/mysql /data

保证新旧目录权限不一致,不一致修改

chown mysql:mysql /data/mysql

编辑my.cnf

[client]

port = 3306

socket = /data/mysql/mysql.sock

default-character-set = utf8

[mysql]

default-character-set=utf8

[mysqld]

datadir=/data/mysql

socket=/data/mysql/mysql.sock

character-set-server=utf8

skip-external-locking

log-bin=mysql-bin

binlog_format=mixed

server-id=1

[mysqld_safe]

log-error=/var/log/mysqld.log

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

查询MySQL默认配置加下顺序

mysql --verbose --help | grep -A 1 'Default options'

Default options are read from the following files in the given order:

/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

启动 mysql

service mysql start

mysql> show variables like '%datadir%';

如果有错误,查看错误日志解决 /var/log/mysqld.log

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐