系统:linux Rhel 5.9 x64

mysql 安装了客户端和服务端

 rpm -ivh  MySQL-server-advanced-5.6.21-1.rhel5.x86_64.rpm

 rpm -ivh MySQL-client-advanced-5.6.21-1.rhel5.x86_64.rpm

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

  1. 关闭服务

    service mysql stop
    
  2. 复制mysql 数据文件到新的目录

    cp -rp /var/lib/mysql  /data
    

    查看原目录的权限,如果新目录的不一致,修改一致,参考

    chown mysql:mysql /data/mysql
    
  3. 编辑my.cnf

    [client]
    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
    lower_case_table_names=1
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    

    参考:`查询MySQL默认配置加下顺序

    /usr/bin/mysql --verbose --help | grep -A 1 'Default options'
    

    `

  4. 启动 mysql

    service mysql start 
    

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

    其它参考:How to Change default MySQL Data Directory in Linux


liujs
277 声望5 粉丝