一、环境
- CentOS Linux release 8.2.2004 (Core)
- MySql:8.0.17(mysql80-community-release-el8-1.noarch.rpm)
二、步骤
1.关闭mysql服务进程
systemctl stop mysqld
2.创建目标目录
mkdir /data/mysql
3.目录授权
# 将目录授权给mysql用户组
chown mysql:mysql /data/mysql
# 更改目录权限
chmod 750 /data/mysql
4.数据移动/拷贝
mv /var/lib/mysql/* /data/mysql/
5.修改配置文件
此前,一般是修改/etc/my.cnf文件,但本文环境下my.cnf文件内容如下:
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
也就是配置内容,放到了/etc/my.cnf.d目录下了。该目录下包括如下文件:
[root@ZSSM01 /]# ls /etc/my.cnf.d
client.cnf mysql-default-authentication-plugin.cnf mysql-server.cnf
显然,需要调整的是服务器端配置。因此,选择修改mysql-server.cnf文件。调整后文件内容如下:
#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld]
# datadir=/var/lib/mysql
datadir=/data/mysql
# socket=/var/lib/mysql/mysql.sock
socket=/data/mysql/mysql.sock
# log-error=/var/log/mysql/mysqld.log
log-error=/data/mysql/log/mysqld.log
pid-file=/run/mysqld/mysqld.pid
6.建立软链接
ln -s /data/mysql/mysql.sock /var/lib/mysql/mysql.sock
7.重启服务
# 启动服务
systemctl start mysqld
# 查看状态
systemctl status mysqld
这篇博客介绍了如何在CentOS8.2系统上将MySQL8.0.17的默认数据文件和日志文件路径进行更改。首先,需要关闭MySQL服务进程,然后创建新的目标目录并授权。接着,移动数据文件,并在/etc/my.cnf.d/mysql-server.cnf配置文件中更新数据存储路径。最后,建立软链接并重启服务以使更改生效。

473

被折叠的 条评论
为什么被折叠?



