我正在尝试将 mysql 程序的所有执行(所有表数据、索引等)移动到 RAM 磁盘上,以进行从常规 SSD 中排除文件 IO 的性能实验。
我开始像往常一样安装 mysql sudo apt install mysql-server
:. 程序开始,mysqld
我可以正常创建数据库。
我还按照此站点上列出的说明创建了一个 RAMDisk:在该位置的 Ubuntu 上创建 RAMDisk/mnt/ramdisk
并使用大小25G
(我有64G
可用的 RAM)。我可以写入这个位置并观察到我的 RAM 开始按应有的方式填满。
现在,我使用以下命令将我的 mysql 库目录复制到此 RAMDisk:
cp -rp /var/lib/mysql /mnt/ramdisk
并符号链接到它,这样我就不必更改文件datadir
中的参数/etc/mysql/mysql.conf.d/mysqld.cnf
。
mv mysql _mysql
ln -s /mnt/ramdisk/mysql mysql
我还更改了权限,以便 MySQL“应该”能够访问 RAMDisk:
root@HOSTNAME:/var/lib# ls -l | grep mysql
lrwxrwxrwx 1 mysql mysql 19 Feb 14 16:45 mysql -> /mnt/ramdisk/mysql/
drwx------ 6 mysql mysql 4096 Feb 14 17:06 _mysql
drwx------ 2 mysql mysql 4096 Feb 14 12:14 mysql-files
drwx------ 2 mysql mysql 4096 Feb 12 17:14 mysql-keyring
drwxr-xr-x 2 root root 4096 Jan 21 06:10 mysql-upgrade
和
root@HOSTNAME:/mnt# ls -l
total 0
drwxrwxrwt 3 mysql mysql 60 Feb 14 17:24 ramdisk
root@HOSTNAME:/mnt/ramdisk# ls -l
total 0
drwx------ 5 mysql mysql 380 Feb 14 16:41 mysql
但是,当我现在尝试重新启动mysqld
程序时,遇到以下错误:
USER@HOSTNAME:/$ sudo /etc/init.d/mysql restart
[sudo] password for USER:
[....] Restarting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
failed!
调查两者systemctl status mysql.service
,journalctl -xe
并没有对问题提供更多见解:
USER@HOSTNAME:/$ systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2020-02-14 17:30:55 PST; 1min 0s ago
Process: 19794 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
Process: 19785 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 17945 (code=exited, status=0/SUCCESS)
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.
Feb 14 17:30:55 HOSTNAME systemd[1]: Stopped MySQL Community Server.
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Start request repeated too quickly.
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb 14 17:30:55 HOSTNAME systemd[1]: Failed to start MySQL Community Server.
对于journalctl -xe
:
-- Unit mysql.service has begun starting up.
Feb 14 17:30:54 HOSTNAME audit[19792]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19792 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Feb 14 17:30:54 HOSTNAME audit[19792]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19792 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Feb 14 17:30:54 HOSTNAME audit[19792]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19792 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=0 ouid=0
Feb 14 17:30:54 HOSTNAME audit[19796]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19796 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=125 ouid=125
Feb 14 17:30:54 HOSTNAME audit[19796]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19796 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=125 ouid=125
Feb 14 17:30:54 HOSTNAME audit[19796]: AVC apparmor="DENIED" operation="mknod" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/HOSTNAME.lower-test" pid=19796 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=125 ouid=125
Feb 14 17:30:54 HOSTNAME audit[19796]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/mnt/ramdisk/mysql/ibdata1" pid=19796 comm="mysqld" requested_mask="wr" denied_mask="wr" fsuid=125 ouid=125
Feb 14 17:30:55 HOSTNAME mysqld[19794]: Initialization of mysqld failed: 0
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Control process exited, code=exited status=1
Feb 14 17:30:55 HOSTNAME systemd[1]: mysql.service: Failed with result 'exit-code'.
Feb 14 17:30:55 HOSTNAME systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mysql.service has failed.
事实证明,问题在于
journalctl -xe
输出正盯着我。更具体地说,apparmor="DENIED"部分。从AskUbuntu上的这个答案:mysql文件夹重定位后的Apparmor错误我能够解决我的问题。我将在下面添加相关细节:
编辑
/etc/apparmor.d/usr.sbin.mysqld
文件。删除/var/lib/mysql
并添加新的 datadir 位置。就我而言,它是重启apparmor:
service systemctl restart apparmor
重启mysql服务:
service mysql start