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


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

相关推荐
ben9518chen2 分钟前
嵌入式linux操作系统简介
linux·运维·服务器
菜鸟笔记本4 分钟前
linux设置定时备份mysql数据
linux·mysql·oracle
千寻技术帮5 分钟前
10347_基于Springboot的新疆旅游管理系统
spring boot·mysql·旅游·在线旅游
majingming1237 分钟前
ubuntu下的交叉编译
linux·运维·ubuntu
shchojj9 分钟前
ubuntu 因为写错pam.d文件引起的sudo权限丢失
linux·运维·ubuntu
funfan051725 分钟前
【运维】Linux/Debian系统时间校准方法简记
linux·运维·debian
Florence231 小时前
cuFuncSetCacheConfig
linux·运维·服务器
Petal9909121 小时前
内核调试:Linux编译内核源码为deb并更新内核
linux·运维·服务器
Web项目开发1 小时前
Mysql创建索引的SQL脚本,复制粘贴即可使用
数据库·sql·mysql
用户467244544991 小时前
Linux 进程管理
linux