Debian 修改mysql datadir 路径

2024-10-17  本文已影响0人  Rinaloving

环境

操作

1. 停止 mysql 服务
systemctl stop mysql
2. 创建文件夹并授权
root@cfl:/home# mkdir lib
root@cfl:/home# mkdir lib/mysql
root@cfl:/home# chmod -R 777 lib/
root@cfl:/home# chmod -R 777 lib/mysql/
3. 修改 my.cnf 文件
vim /etc/my.cnf

修改前文件内容

[mysqld]
basedir=/usr/local/mysql
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
lower_case_table_names=1
[client]
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8

修改后文件内容

[mysqld]
basedir=/usr/local/mysql
datadir=/home/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
lower_case_table_names=1
[client]
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
4. 转移数据内容到新路径下
 sudo cp -R -p /var/lib/mysql/* /home/lib/mysql/
5. 重启 mysql服务
 systemctl start mysql
上一篇 下一篇

猜你喜欢

热点阅读