欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Linux下修改MySQL数据库数据文件路径的步骤

程序员文章站 2022-06-07 23:07:18
使用rpm安装方式安装完mysql数据库后,数据文件的默认路径为/var/lib/mysql,然而根目录并不适合用于存储数据文件。 原路径:/var/lib/mysql 目标路径:...

使用rpm安装方式安装完mysql数据库后,数据文件的默认路径为/var/lib/mysql,然而根目录并不适合用于存储数据文件。

原路径:/var/lib/mysql

目标路径:/home/mysql_data/mysql

linux系统版本:centos7.6

mysql数据库版本:5.7.25

步骤:

1、创建目标路径

mkdir -p /home/mysql_data

2、关闭mysql

systemctl stop mysqld

3、复制数据文件

cp -arp /var/lib/mysql /home/mysql_data

4、修改配置文件/etc/my.cnf

将datadir和socket中的原路径修改为目标路径

datadir=/home/mysql_data/mysql
socket=/home/mysql_data/mysql/mysql.sock

5、启动mysql服务

systemctl start mysqld

note:

1、报错如下:

2019-12-22t08:32:42.430564z 0 [error] innodb: operating system error number 13 in a file operation.
2019-12-22t08:32:42.430599z 0 [error] innodb: the error means mysqld does not have the access rights to the directory.
2019-12-22t08:32:42.430616z 0 [note] innodb: creating shared tablespace for temporary tables
2019-12-22t08:32:42.430898z 0 [error] innodb: the innodb_temporary data file 'ibtmp1' must be writable
2019-12-22t08:32:42.430923z 0 [error] innodb: the innodb_temporary data file 'ibtmp1' must be writable
2019-12-22t08:32:42.430936z 0 [error] innodb: could not create the shared innodb_temporary.
2019-12-22t08:32:42.430952z 0 [error] innodb: plugin initialization aborted with error generic error
2019-12-22t08:32:43.038973z 0 [error] innodb: operating system error number 13 in a file operation.
2019-12-22t08:32:43.039021z 0 [error] innodb: the error means mysqld does not have the access rights to the directory.
2019-12-22t08:32:43.039037z 0 [error] plugin 'innodb' init function returned error.
2019-12-22t08:32:43.039046z 0 [error] plugin 'innodb' registration as a storage engine failed.
2019-12-22t08:32:43.039056z 0 [error] failed to initialize builtin plugins.
2019-12-22t08:32:43.039063z 0 [error] aborting

解决:

执行命令:

setenforce 1

再重新启动

2、报错如下:

can't connect to local mysql server through socket '/var/lib/mysql/mysql.sock'

解决:

修改配置文件my.cnf,添加或修改如下配置:

[client]
socket = /home/mysql_data/mysql/mysql.sock

总结

以上所述是小编给大家介绍的linux下修改mysql数据库数据文件路径,希望对大家有所帮助