我正在尝试在我的 Ubuntu 22.04 服务器上获取只读副本。我要离开这篇文章了: 同一台机器上的 MySQL 主从复制。我陷入了安装第二个 MySQL 实例;这篇文章引用了
mysql_install_db
,据我了解,它在 MySQL 8 中已被弃用
我正在使用:
mysql Ver 8.0.33-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))
我的问题:在8.0.33-0ubuntu0.22.04.2上,如何解决权限问题 问题,以便我可以安装我的第二个 MySQL 实例 /var/lib/mysql_replica
当我运行以下命令时:
sudo mysqld --initialize --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql_replica
我收到此错误:
sudo mysqld --initialize --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql_replica/
mysqld: Can't create directory '/var/lib/mysql_replica/' (OS errno 13 - Permission denied)
2023-07-08T11:40:34.102368Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.33-0ubuntu0.22.04.2) initializing of server in progress as process 92415
2023-07-08T11:40:34.102400Z 0 [ERROR] [MY-010338] [Server] Can't find error-message file '/var/lib/mysql/share/mysql/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2023-07-08T11:40:34.103522Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql_replica/ is unusable. You can remove all files that the server added to it.
2023-07-08T11:40:34.103809Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-07-08T11:40:34.104059Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.33-0ubuntu0.22.04.2) (Ubuntu).
我尝试过删除/重新创建目录、将ubuntu添加到mysql用户组、设置权限并重新运行,但无济于事;我遇到与上面相同的错误
sudo systemctl stop mysql
sudo rm -rf /var/lib/mysql_replica
sudo mkdir /var/lib/mysql_replica
sudo usermod -aG mysql ubuntu
sudo chown -R ubuntu:mysql /var/lib/mysql_replica
sudo chmod 750 /var/lib/mysql_replica
当我追踪 AppArmor 日志时,我得到以下信息:
sudo tail -f /var/log/syslog | grep -i apparmor
Jul 8 11:40:29 ip-#-#-#-# kernel: [514029.361780] audit: type=1400 audit(1688816429.849:66): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/usr/lib/connman/scripts/dhclient-script" pid=92405 comm="apparmor_parser"
Jul 8 11:40:29 ip-#-#-#-# kernel: [514029.361785] audit: type=1400 audit(1688816429.849:67): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="/{,usr/}sbin/dhclient" pid=92405 comm="apparmor_parser"
Jul 8 11:40:29 ip-#-#-#-# apparmor.systemd[92410]: Skipping profile in /etc/apparmor.d/disable: usr.sbin.mysqld
Jul 8 11:40:29 ip-#-#-#-# apparmor.systemd[92411]: Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
Jul 8 11:40:29 ip-#-#-#-# systemd[1]: Reloaded Load AppArmor profiles.
Jul 8 11:50:38 ip-#-#-#-# kernel: [514638.054645] audit: type=1400 audit(1688817038.472:73): apparmor="DENIED" operation="open" class="file" profile="/usr/sbin/mysqld" name="/var/lib/mysql_replica/" pid=92478 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Jul 8 11:51:01 ip-#-#-#-# kernel: [514661.361667] audit: type=1400 audit(1688817061.778:74): apparmor="DENIED" operation="open" class="file" profile="/usr/sbin/mysqld" name="/var/lib/mysql_replica/" pid=92504 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Jul 8 11:51:49 ip-#-#-#-# kernel: [514709.257782] audit: type=1400 audit(1688817109.664:75): apparmor="DENIED" operation="open" class="file" profile="/usr/sbin/mysqld" name="/var/lib/mysql_replica/" pid=92529 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=0 ouid=1000
Jul 8 11:56:10 ip-#-#-#-# kernel: [514970.372665] audit: type=1400 audit(1688817370.749:76): apparmor="DENIED" operation="mkdir" class="file" profile="/usr/sbin/mysqld" name="/var/lib/mysql_slave/" pid=92569 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
根据文章中的AppArmor中的其他安全设置,我已将
/etc/apparmor.d/usr.sbin.mysqld
更新为:
/var/lib/mysql_replica/ r,
/var/lib/mysql_replica/** rwk,
/var/log/mysql_replica/ r,
/var/log/mysql_replica/* rw,
/var/run/mysqld/mysqld_replica.pid rw,
/var/run/mysqld/mysqld_replica.sock w,
/run/mysqld/mysqld_replica.pid rw,
/run/mysqld/mysqld_replica.sock w,
sudo systemctl reload apparmor
& sudo systemctl status apparmor
sudo systemctl stop apparmor
此时,我不知所措;我知道存在权限问题,我只是不明白什么不起作用。
...典型的捂脸时刻在发帖后不久就出现了
我需要跑步
sudo reboot
现在可以了:
sudo mysqld --initialize --user=mysql --datadir=/var/lib/mysql_replica
遇到类似问题!可能这是由于 dir
/var/lib/mysql_replica/
可能安装在其他磁盘或其他分区上,并且 AppArmor
阻止 mysql 访问该目录。
MySQL 在这方面存在错误。 错误 #82281 - mysqld --initialize 报告“权限被拒绝”,无论权限如何
解决方法: 禁用 AppArmor 的 mysqld 配置文件
sudo aa-disable /usr/sbin/mysqld