在Ubuntu中atp安装的mysql,默认数据目录在/var/lib/mysql ,添加了一块硬盘,需要将数据目录改为独立硬盘中。
修改mysql配置文件后重启报错,提示权限拒绝,修改了目录属主属组仍旧不行。
root@iZwz9g269i424nee31ly7yZ:/mysql/data# systemctl status mysql ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2024-04-07 17:14:53 CST; 10s ago Process: 891921 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Process: 891929 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE) Main PID: 891929 (code=exited, status=1/FAILURE) Status: "Server shutdown complete" Error: 13 (Permission denied) Apr 07 17:14:53 iZwz9g269i424nee31ly7yZ systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5. Apr 07 17:14:53 iZwz9g269i424nee31ly7yZ systemd[1]: Stopped MySQL Community Server. Apr 07 17:14:53 iZwz9g269i424nee31ly7yZ systemd[1]: mysql.service: Start request repeated too quickly. Apr 07 17:14:53 iZwz9g269i424nee31ly7yZ systemd[1]: mysql.service: Failed with result 'exit-code'. Apr 07 17:14:53 iZwz9g269i424nee31ly7yZ systemd[1]: Failed to start MySQL Community Server.
最终发现是apparmor这个服务导致的,apparmor是与selinux类似的访问控制机制。
root@iZwz9g269i424nee31ly7yZ:~# cat /etc/apparmor.d/usr.sbin.mysqld 将 # Allow data dir access /var/lib/mysql/ r /var/lib/mysql/** rwk 改为 # Allow data dir access /mysql/data/ r, /mysql/data/** rwk, # 重启apparmor及mysql root@iZwz9g269i424nee31ly7yZ:~# /etc/init.d/apparmor restart root@iZwz9g269i424nee31ly7yZ:~# systemctl restart mysql
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/5428.html