Home >Database >Mysql Tutorial >centos mysql 修改数据库目录_MySQL

centos mysql 修改数据库目录_MySQL

WBOY
WBOYOriginal
2016-06-01 13:25:43919browse

CentOS

bitsCN.com

MySQL默认的数据文件存储目录 /var/lib/mysql,现在要把目录修改为/home/data/mysql
cd /home
mkdir data //在home目录下建data目录
mysqladmin -u root -p shutdown //停止MySQL服务进程:
mv /var/lib/mysql /home/data/ //移动目录
cp /etc/my.cnf /etc/my.cnf //在/etc/目录下找my.cnf配置文件

[如果找不到,可到/usr/share/mysql/下找到*.cnf文件,拷一个到/etc/并改名为my.cnf,
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
]
编辑MySQL的配置文件/etc/my.cnf,为MySQL能够正常工作,指明mysql.sock文件的产生位置,
修改
socket=/var/lib/mysql/mysql.sock
成为:
socket=/home/mysql/mysql.sock

操作过程
vi  my.cnf
# The MySQL server
[mysqld]
port = 3306
#socket = /var/lib/mysql/mysql.sock //原内容,为了稳妥用“#”注释此行,加上下面这行
socket  = /home/data/mysql/mysql.sock

修改MySQL启动脚本/etc/rc.d/init.d/mysql
修改
datadir=/var/lib/mysql
修改成:
datadir=home/data/mysql

重新启动MySQL服务
/etc/rc.d/init.d/mysql start
或reboot命令重启Linux

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn