CentOS修改MySQL数据目录后重启失败的问题及解决方案

文章目录

问题描述

由于磁盘空间不足,想要迁移MySQL数据存储目录,修改完 my.cnf 配置文件之后,重启失败(如下图),查看 mysqld.log 之后看到如下报错内容(如下图):

shell 复制代码
2025-10-17T02:09:52.864185Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2025-10-17T02:09:53.081737Z 0 [Warning] [MY-010091] [Server] Can't create test file /home/mysql/mysqld_tmp_file_case_insensitive_test.lower-test
2025-10-17T02:09:53.081810Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.4.6) starting as process 2918986
2025-10-17T02:09:53.084738Z 0 [Warning] [MY-010091] [Server] Can't create test file /home/mysql/mysqld_tmp_file_case_insensitive_test.lower-test
2025-10-17T02:09:53.084744Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /home/mysql/ is case insensitive
mysqld: File './binlog.index' not found (OS errno 13 - Permission denied)
2025-10-17T02:09:53.085953Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-10-17T02:09:53.087281Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.4.6)  MySQL Community Server - GPL.
2025-10-17T02:09:53.087301Z 0 [System] [MY-015016] [Server] MySQL Server - end.

解决方案

经排查发现,是 selinux 配置限制,需要进行如下配置,即可解决:

shell 复制代码
# 添加正确的类型(mysqld_db_t)
sudo semanage fcontext -a -t mysqld_db_t "/home/mysql(/.*)?"

# 应用上下文
sudo restorecon -Rv /home/mysql/

重启 MySQL 服务:

复制代码
systemctl restart mysqld


********************************* 只要思想不滑坡,办法总比困难多*********************************

相关推荐
Apipi*3 小时前
30天速通Linux 第六章信号及信号处理
linux·运维·信号处理
天启HTTP4 小时前
爬虫防封核心原理:IP轮换机制与风控规避逻辑
linux·服务器·网络·爬虫·tcp/ip
广州浮点FLOATLIC7 小时前
许可证服务器迁移后软件打不开:研发 IT 怎样定位连接问题
linux·服务器·数据库
程序员Sunday7 小时前
MySQL 为什么使用 B+ 树索引?把范围查询、回表和覆盖索引连起来
数据库·mysql
BLUcoding7 小时前
接口服务公网超时排查记录:SecureRandom 阻塞问题分析与解决
java·linux·springboot·aes·securerandom
AIgorithmGEEK7 小时前
[Linux]从手写报头到内核套路:序列化、反序列化与自定义协议全链路
linux·运维·服务器·网络·序列化·反序列化
Yyyyyy~7 小时前
[ Mysql ] 库的操作
mysql
Nil2087 小时前
leetcode 139单词拆分
linux·运维·服务器
Starry-sky(jing)7 小时前
BUG: unable to handle kernel paging request 完整排查:dmesg 四要素与三路定罪
linux·运维·服务器·内核·排障
mounter6257 小时前
从硬件互连到操作系统变革:CXL 技术演进与 Linux 内核工程挑战
linux·运维·服务器