我在 14.04 上运行 mysqld,使用非标准的 --datadir (/usr/local/mysqld-test) 和端口 (33306)。升级到 16.04 后,我无法再启动我的测试 mysqld,因此,按照说明这里并链接到错误中这里,我最终做到了:
sudo apt purge mariadb-client-10.0 mariadb-common mysql-client mysql-client-5.7 mysql-client-core-5.7 mysql-common dbconfig-mysql
sudo apt-get install mysql-client mysql-server
(在此过程中,它卸载了 amarok!? 咆哮
这仍然不起作用,所以我最终摧毁了我的整个系统/usr/local/mysqld-test
(故意的;理论上我有脚本来重建它)。mysql_install_db
我之前使用的命令现在已被弃用,并且似乎无法理解该-P 33306
参数,因此我尝试使用mysqld --initialize-insecure
。
以下是我正在做的事情:
mysqld --initialize-insecure --basedir=/usr/local/mysqld-test --datadir=/usr/local/mysqld-test/data
它失败:
mysqld: Can't create directory '/usr/local/mysqld-test/data/' (Errcode: 13 - Permission denied)
2016-11-02T10:21:37.547443Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-11-02T10:21:37.549183Z 0 [ERROR] Aborting
嗯。我以为我已经让它可全世界写入了:
$ ls -al /usr/local/mysqld-test
total 8
drwxrwxrwx 2 kuhrusty kuhrusty 4096 Nov 2 03:13 .
drwxr-xr-x 20 root root 4096 Nov 2 03:13 ..
什么鬼?我们来试试strace
:
execve("/usr/sbin/mysqld", ["mysqld", "--initialize-insecure", "--basedir=/usr/local/mysqld-test", "--datadir=/usr/local/mysqld-test"...], [/* 69 vars */]) = 0
...
它映射一堆共享库,设置一些信号处理程序,然后查找配置文件(我认为我没有弄乱它 - 我手动启动它,传递--datadir
,-P
等):
stat("/etc/my.cnf", 0x7ffe13e99af0) = -1 ENOENT (No such file or directory)
stat("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=682, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=682, ...}) = 0
read(3, "#\n# The MySQL database server co"..., 4096) = 682
open("/etc/mysql/conf.d/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4
fstat(4, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
brk(0x271d000) = 0x271d000
getdents(4, /* 4 entries */, 32768) = 120
getdents(4, /* 0 entries */, 32768) = 0
close(4) = 0
stat("/etc/mysql/conf.d/mysql.cnf", {st_mode=S_IFREG|0644, st_size=8, ...}) = 0
open("/etc/mysql/conf.d/mysql.cnf", O_RDONLY) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=8, ...}) = 0
read(4, "[mysql]\n", 4096) = 8
read(4, "", 4096) = 0
close(4) = 0
stat("/etc/mysql/conf.d/mysqldump.cnf", {st_mode=S_IFREG|0644, st_size=55, ...}) = 0
open("/etc/mysql/conf.d/mysqldump.cnf", O_RDONLY) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=55, ...}) = 0
read(4, "[mysqldump]\nquick\nquote-names\nma"..., 4096) = 55
read(4, "", 4096) = 0
close(4) = 0
brk(0x2713000) = 0x2713000
brk(0x270a000) = 0x270a000
open("/etc/mysql/mysql.conf.d/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 4
fstat(4, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
getdents(4, /* 4 entries */, 32768) = 128
getdents(4, /* 0 entries */, 32768) = 0
close(4) = 0
stat("/etc/mysql/mysql.conf.d/mysqld.cnf", {st_mode=S_IFREG|0644, st_size=3028, ...}) = 0
open("/etc/mysql/mysql.conf.d/mysqld.cnf", O_RDONLY) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=3028, ...}) = 0
read(4, "#\n# The MySQL database server co"..., 4096) = 3028
read(4, "", 4096) = 0
close(4) = 0
stat("/etc/mysql/mysql.conf.d/mysqld_safe_syslog.cnf", {st_mode=S_IFREG|0644, st_size=21, ...}) = 0
open("/etc/mysql/mysql.conf.d/mysqld_safe_syslog.cnf", O_RDONLY) = 4
fstat(4, {st_mode=S_IFREG|0644, st_size=21, ...}) = 0
read(4, "[mysqld_safe]\nsyslog\n", 4096) = 21
read(4, "", 4096) = 0
close(4) = 0
read(3, "", 4096) = 0
close(3) = 0
stat("/home/kuhrusty/.my.cnf", 0x7ffe13e99af0) = -1 ENOENT (No such file or directory)
stat("/home/kuhrusty/.mylogin.cnf", 0x7ffe13e99af0) = -1 ENOENT (No such file or directory)
getrlimit(RLIMIT_NOFILE, {rlim_cur=1024, rlim_max=64*1024}) = 0
setrlimit(RLIMIT_NOFILE, {rlim_cur=5000, rlim_max=5000}) = 0
getrlimit(RLIMIT_NOFILE, {rlim_cur=5000, rlim_max=5000}) = 0
umask(026) = 02
open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2845, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=2845, ...}) = 0
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\0\5\0\0\0\0"..., 4096) = 2845
lseek(3, -1811, SEEK_CUR) = 1034
read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\0\5\0\0\0\0"..., 4096) = 1811
close(3) = 0
uname({sysname="Linux", nodename="tentacle", ...}) = 0
brk(0x2732000) = 0x2732000
brk(0x2724000) = 0x2724000
lstat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/local/mysqld-test", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
lstat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/local/mysqld-test", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
lstat("/usr/local/mysqld-test/data", 0x7ffe13e9d1d0) = -1 ENOENT (No such file or directory)
open("/usr/share/mysql/english/errmsg.sys", O_RDONLY) = 3
read(3, "\376\376\3\1\1\0\335\26\1\0008\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\10\0", 32) = 32
read(3, "\0\0\0\0\10\0\0\0\20\0\0\0\23\0\0\0\27\0\0\0D\0\0\0m\0\0\0\231\0\0\0"..., 4320) = 4320
read(3, "hashchk\0isamchk\0NO\0YES\0Can't cre"..., 71389) = 71389
close(3) = 0
stat("/usr/local/mysqld-test/share/mysql/charsets/Index.xml", 0x7ffe13e9e2e0) = -1 ENOENT (No such file or directory)
futex(0x1ddcf48, FUTEX_WAKE_PRIVATE, 2147483647) = 0
brk(0x2745000) = 0x2745000
open("/usr/local/mysqld-test/data/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
mkdir("/usr/local/mysqld-test/data/", 0750) = -1 EACCES (Permission denied)
好的,现在我思考这就是问题所在(笔记:确保滚动到底部)...但是为什么? 任何人可以在那里创建一个文件!
write(2, "mysqld: ", 8) = 8
write(2, "Can't create directory '/usr/loc"..., 87) = 87
write(2, "\n", 1) = 1
mysqld: Can't create directory '/usr/local/mysqld-test/data/' (Errcode: 13 - Permission denied)
什么鬼???因为这个问题,从 14.04 升级到 16.04 现在是我一生中第三大错误了……我感觉我遭受了一次脑外伤,忘记了如何阅读。那些权限是正确的,对吧???在以下环境mysqld --initialize
下运行sudo
没有区别。我是不是做错了什么非常愚蠢的事情?
答案1
ARGHH AppArmor 让我失望了。第二个答案这里是什么给了我需要查看日志的提示:
[137519.814104] audit: type=1400 audit(1478218238.219:177): apparmor="DENIED" operation="mkdir" profile="/usr/sbin/mysqld" name="/usr/local/mysqld-test/data/" pid=7126 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=1000 ouid=1000
下列的这些说明,我禁用了 MySQL 的 AppArmor:
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
cd /etc/apparmor.d/disable
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld .
然后确认mysqld不再处于强制模式:
sudo aa-status
然后mysqld --initialize-insecure
按照我两天前预期的方式启动并运行它。
(为什么/如何会在 14.04 -> 16.04 升级期间安装/启用 AppArmor?在此之前,我认为我从未听说过 AppArmor;“您的内容将不再像以前那样工作”似乎是我应该在升级期间获得的那种信息!)