mysql修改路径 Linux_Linux下修改MySQL数据库数据文件路径

本文详细描述了如何在CentOS 7.6系统中,通过将MySQL数据文件从/var/lib/mysql迁移到/home/mysql_data,并在遇到权限错误时,如何正确设置文件权限以确保InnoDB插件的正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

亲测可用,若有疑问请私信

使用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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值