MariaDB 将数据库移动到用户主目录

MariaDB 将数据库移动到用户主目录

我正在尝试将一些数据库移动到用户的主目录,但在 Ubuntu 20.04 LTS 上遇到问题。以下是我所做的:为此设置创建了一个新数据库。将其命名为“测试”

  1. 在 /home/admin/ 中创建“数据库”目录
  2. 将 /home/admin/databases 的所有权更改为 mysql:mysql
  3. 移动数据库目录mv /var/lib/mysql/test /home/admin/databases/test
  4. 创建符号链接sudo -u mysql ln -s /home/admin/databases/test /var/lib/mysql/test
  5. 重启 MariaDB 服务

现在我在系统日志中收到这些错误

[ERROR] InnoDB: Operating system error number 13 in a file operation.
[ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
[ERROR] InnoDB: Cannot open datafile for read-only: './test/test.ibd' OS error: 81
[ERROR] InnoDB: Operating system error number 13 in a file operation.
[ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
[ERROR] InnoDB: Could not find a valid tablespace file for ``test`.`test``. Please refer to https://mariadb.com/kb/en/innodb-data-dictionary-troubleshooting/ for how to resolve the issue.
[Warning] InnoDB: Ignoring tablespace for `test`.`test` because it could not be opened.

我已经尝试授予 mysql 用户对 /home 和 /home/admin 的所有文件权限(使用 setfacl)。

getfacl /home
# file: home
# owner: root
# group: root
user::rwx
user:mysql:rwx
group::r-x
mask::rwx
other::r-x

getfacl /home/admin
#file: home/admin
# owner: root
# group: root
user::rwx
user:mysql:rwx
user:admin:rwx
group::r-x
group:admin:r-x
mask::rwx
other::r-x

mysql/mariadb 也没有 apparmor 规则:

apparmor module is loaded.
15 profiles are loaded.
14 profiles are in enforce mode.
   /usr/bin/freshclam
   /usr/bin/man
   /usr/lib/NetworkManager/nm-dhcp-client.action
   /usr/lib/NetworkManager/nm-dhcp-helper
   /usr/lib/connman/scripts/dhclient-script
   /usr/sbin/clamd
   /usr/sbin/tcpdump
   /{,usr/}sbin/dhclient
   docker-default
   lsb_release
   man_filter
   man_groff
   nvidia_modprobe
   nvidia_modprobe//kmod
1 profiles are in complain mode.
   /usr/sbin/named
3 processes have profiles defined.
0 processes are in enforce mode.
0 processes are in complain mode.
3 processes are unconfined but have a profile defined.
   /usr/bin/freshclam (571) 
   /usr/sbin/clamd (455) 
   /usr/sbin/named (495) 

有什么想法吗?提前致谢。

答案1

我花了一段时间,但在发布问题后我就解决了它。

/var/lib/systemd/system/mariadb.service一条线上

ProtectHome=true

更改为false并且现在可以工作了。

编辑:在较新的 ubuntu 版本中,该文件位于此处/usr/lib/systemd/system/mariadb.service

相关内容