当前位置: 首页 > news >正文

ubuntu22.04 mysql 移动数据目录后 systemctl start mysql无法启动的解决方案

ubuntu22.04 mysql 移动数据目录后 systemctl start mysql无法启动的解决方案

默认安装的数据目录在/var/lib/mysql下

我把它移到了/data/mysql/data下,修改mysql数据文件夹

root@iZbp:~# nano /etc/mysql/my.cnfGNU nano 6.2                                                /etc/mysql/my.cnf                                                         
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/[mysqld]
datadir=/data/mysql/data

执行 systemctl start mysql如下所示:

root@iZbp:~# systemctl start mysql
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xeu mysql.service" for details.
root@iZbp:~# journalctl -xeu mysql.service            
░░ Support: http://www.ubuntu.com/support
░░ 
░░ The unit mysql.service has entered the 'failed' state with result 'exit-code'.
Aug 12 16:58:21 iZbp systemd[1]: Failed to start MySQL Community Server.
░░ Subject: A start job for unit mysql.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit mysql.service has finished with a failure.
░░ 
░░ The job identifier is 7805 and the job result is failed.
Aug 12 16:58:21 iZbp systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ Automatic restarting of the unit mysql.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
Aug 12 16:58:21 iZbp systemd[1]: Stopped MySQL Community Server.
░░ Subject: A stop job for unit mysql.service has finished
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A stop job for unit mysql.service has finished.
░░ 
░░ The job identifier is 7897 and the job result is done.
Aug 12 16:58:21 iZbp systemd[1]: mysql.service: Start request repeated too quickly.
Aug 12 16:58:21 iZbp systemd[1]: mysql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ The unit mysql.service has entered the 'failed' state with result 'exit-code'.
Aug 12 16:58:21 iZbp systemd[1]: Failed to start MySQL Community Server.
░░ Subject: A start job for unit mysql.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit mysql.service has finished with a failure.
░░ 
░░ The job identifier is 7897 and the job result is failed.
Aug 12 16:58:28 iZbp systemd[1]: mysql.service: Start request repeated too quickly.
Aug 12 16:58:28 iZbp systemd[1]: mysql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ The unit mysql.service has entered the 'failed' state with result 'exit-code'.
Aug 12 16:58:28 iZbp systemd[1]: Failed to start MySQL Community Server.
░░ Subject: A start job for unit mysql.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit mysql.service has finished with a failure.
░░ 
░░ The job identifier is 7990 and the job result is failed.

其中 /data/mysql/data已chown -R mysql:mysql了,还是不行

最终找到的原因和解决方法
/etc/apparmor.d/usr.sbin.mysqld文件有对权限的控制,需要修改相关项,如下所示

root@iZbp:~# sudo nano /etc/apparmor.d/usr.sbin.mysqld
# vim:syntax=apparmor
# Last Modified: Tue Feb 09 15:28:30 2016
#include <tunables/global>/usr/sbin/mysqld {#include <abstractions/base>#include <abstractions/nameservice>#include <abstractions/user-tmp>#include <abstractions/mysql>#include <abstractions/winbind># Allow system resource access/proc/*/status r,/sys/devices/system/cpu/ r,/sys/devices/system/node/ r,/sys/devices/system/node/** r,capability sys_resource,capability dac_override,capability dac_read_search,capability setuid,capability setgid,# Allow network accessnetwork tcp,/etc/hosts.allow r,/etc/hosts.deny r,# Allow config access/etc/mysql/** r,# Allow pid, socket, socket lock file access/var/run/mysqld/mysqld.pid rw,/var/run/mysqld/mysqld.sock rw,/var/run/mysqld/mysqld.sock.lock rw,/var/run/mysqld/mysqlx.sock rw,/var/run/mysqld/mysqlx.sock.lock rw,
# vim:syntax=apparmor
# Last Modified: Tue Feb 09 15:28:30 2016
#include <tunables/global>/usr/sbin/mysqld {#include <abstractions/base>#include <abstractions/nameservice>#include <abstractions/user-tmp>#include <abstractions/mysql>#include <abstractions/winbind># Allow system resource access/proc/*/status r,/sys/devices/system/cpu/ r,/sys/devices/system/node/ r,/sys/devices/system/node/** r,capability sys_resource,capability dac_override,capability dac_read_search,capability setuid,capability setgid,# Allow network accessnetwork tcp,/etc/hosts.allow r,/etc/hosts.deny r,# Allow config access/etc/mysql/** r,# Allow pid, socket, socket lock file access/var/run/mysqld/mysqld.pid rw,/var/run/mysqld/mysqld.sock rw,/var/run/mysqld/mysqld.sock.lock rw,/var/run/mysqld/mysqlx.sock rw,/var/run/mysqld/mysqlx.sock.lock rw,GNU nano 6.2                                         /etc/apparmor.d/usr.sbin.mysqld                                                  /run/mysqld/mysqld.pid rw,/run/mysqld/mysqld.sock rw,/run/mysqld/mysqld.sock.lock rw,/run/mysqld/mysqlx.sock rw,/run/mysqld/mysqlx.sock.lock rw,# Allow systemd notify messages/{,var/}run/systemd/notify w,# Allow execution of server binary/usr/sbin/mysqld mr,/usr/sbin/mysqld-debug mr,# Allow plugin access/usr/lib/mysql/plugin/ r,/usr/lib/mysql/plugin/*.so* mr,/data/mysql/data/plugin/ r,/data/mysql/data/plugin/*.so* mr,# Allow error msg and charset access/usr/share/mysql/ r,/usr/share/mysql/** r,# Allow data dir access/var/lib/mysql/ r,/var/lib/mysql/** rwk,/data/mysql/data/ r,/data/mysql/data/** rwk,# Allow data files dir access/var/lib/mysql-files/ r,/var/lib/mysql-files/** rwk,# Allow keyring dir access/var/lib/mysql-keyring/ r,/var/lib/mysql-keyring/** rwk,# Allow log file access/var/log/mysql.err rw,/var/log/mysql.log rw,/var/log/mysql/ r,/var/log/mysql/** rw,# Allow read access to mecab files/var/lib/mecab/dic/ipadic-utf8/** r,# Allow read access to OpenSSL config/etc/ssl/openssl.cnf r,# Site-specific additions and overrides. See local/README for details.#include <local/usr.sbin.mysqld>
}

我修改了两项

Allow plugin access

# Allow plugin access/usr/lib/mysql/plugin/ r,/usr/lib/mysql/plugin/*.so* mr,/data/mysql/data/plugin/ r,/data/mysql/data/plugin/*.so* mr,

Allow data dir access

# Allow data dir access/var/lib/mysql/ r,/var/lib/mysql/** rwk,/data/mysql/data/ r,/data/mysql/data/** rwk,

增加新的目标文件的访问权限,Ctrl+O 保存 Ctrl+X退出编辑。

再执行

root@iZbp:~# systemctl stop mysql
root@iZbp:~# systemctl start mysql

正常启动

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 1. windows搭建Kafka教程
  • [nsight compute使用指南] 查看存储体冲突
  • Halcon阈值处理的几种分割方法
  • 【MySQL】事务管理
  • Redis单线程模式
  • stm32入门学习14-电源控制
  • vue2中使用i18n配置elementUi切换语言
  • 数学基础 -- 卷积与矩阵乘法的区别
  • 基于R语言遥感随机森林建模与空间预测;遥感数据处理与特征提取;数据分析与可视化
  • 央企数据架构师徐智确认出席「第六届数据智能高峰论坛」
  • 容器化部署ES集群
  • 得到任务式 大模型应用开发学习方案
  • 【ARM CoreLink 系列 5.5 -- CI-700 Debug trace and PMU 】
  • Elasticsearch Nested类型详解与实战
  • 中小企业文档管理最佳方案:7个热门工具
  • 2019年如何成为全栈工程师?
  • Centos6.8 使用rpm安装mysql5.7
  • emacs初体验
  • express + mock 让前后台并行开发
  • Facebook AccountKit 接入的坑点
  • Laravel 实践之路: 数据库迁移与数据填充
  • Nacos系列:Nacos的Java SDK使用
  • 聊聊sentinel的DegradeSlot
  • 三分钟教你同步 Visual Studio Code 设置
  • 适配mpvue平台的的微信小程序日历组件mpvue-calendar
  • 文本多行溢出显示...之最后一行不到行尾的解决
  • 优化 Vue 项目编译文件大小
  • 从如何停掉 Promise 链说起
  • ​经​纬​恒​润​二​面​​三​七​互​娱​一​面​​元​象​二​面​
  • # 安徽锐锋科技IDMS系统简介
  • ###项目技术发展史
  • #Linux(帮助手册)
  • #设计模式#4.6 Flyweight(享元) 对象结构型模式
  • #数学建模# 线性规划问题的Matlab求解
  • (Arcgis)Python编程批量将HDF5文件转换为TIFF格式并应用地理转换和投影信息
  • (Redis使用系列) SpringBoot中Redis的RedisConfig 二
  • (阿里巴巴 dubbo,有数据库,可执行 )dubbo zookeeper spring demo
  • (第61天)多租户架构(CDB/PDB)
  • (三)终结任务
  • (算法)大数的进制转换
  • (五)activiti-modeler 编辑器初步优化
  • (译)计算距离、方位和更多经纬度之间的点
  • (转)为C# Windows服务添加安装程序
  • .libPaths()设置包加载目录
  • .NET Core 中的路径问题
  • .NET_WebForm_layui控件使用及与webform联合使用
  • .NetCore部署微服务(二)
  • .NET应用架构设计:原则、模式与实践 目录预览
  • .Net转Java自学之路—SpringMVC框架篇六(异常处理)
  • .vimrc 配置项
  • /etc/skel 目录作用
  • ::什么意思
  • @PostConstruct 注解的方法用于资源的初始化
  • @selector(..)警告提示
  • @zabbix数据库历史与趋势数据占用优化(mysql存储查询)