Home >Database >Mysql Tutorial >CentOS修改MySql数据库目录datadir_MySQL

CentOS修改MySql数据库目录datadir_MySQL

WBOY
WBOYOriginal
2016-06-01 11:52:36927browse

service mysqld stop //停止mysql服务
cp -rf /var/lib/mysql /home/data //复制默认的mysql数据库目录
chown -R mysql:mysql /home/data //给新的目录授权
 

//修改my.cnf, 为确保没问题, 可以将以前的配置注释掉或者cp一份
vi /etc/my.cnf
datadir=/home/data
socket=/home/data/mysql.sock


//修改mysqld
vi /etc/init.d/mysqld
datadir "/home/data"


service mysqld start //启动mysql


如果启动失败, 使用setenforce 0命令,然后再启动一次试试
----------------------------------------------------------
启动成功之后, 如果使用mysql -u root -p 连接提示/var/lib/mysql/mysql.sock什么错误的话, 那么请修改下面这些配置, 就可以连接了.
vi /etc/my.cnf

[mysql.server]
user=mysql
datadir=/home/data
[client]
socket=/home/data/mysql.sock

 

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