Linux下修改MySQL数据库数据文件路径
程序员文章站
2023-08-30 21:01:52
使用rpm安装方式安装完MySQL数据库后,数据文件的默认路径为/var/lib/mysql,然而根目录并不适合用于存储数据文件。 原路径:/var/lib/mysql 目标路径:/home/mysql_data/mysql Linux系统版本:centos7.6 MySQL数据库版本:5.7.25 ......
使用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、关闭mysqlsystemctl 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
上一篇: 手册