我想将 MySQL 安装的默认时区设置为 UTC。我的系统时区是澳大利亚/布里斯班,我想保留原样,我只想设置 MySQL 的默认时区。我已将以下行添加到/etc/mysql/mysql.conf.d/mysqld.cnf
default_time_zone=UTC
但是现在我的 mysql.service 无法启动。
systemctl start mysql.service
给我:
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
systemctl status mysql.service
告诉我:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: activating (start-post) (Result: exit-code) since Thu 2018-01-11 09:36:12 AEST; 11s ago
Process: 556 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Process: 549 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 556 (code=exited, status=1/FAILURE); Control PID: 557 (mysql-systemd-s)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/mysql.service
└─control
├─557 /bin/bash /usr/share/mysql/mysql-systemd-start post
└─606 sleep 1
Jan 11 09:36:12 irregular-apocalypse systemd[1]: Starting MySQL Community Server...
Jan 11 09:36:14 irregular-apocalypse systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
journalctl -xe
给我:
Jan 11 09:37:15 irregular-apocalypse systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mysql.service has begun starting up.
Jan 11 09:37:15 irregular-apocalypse audit[757]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/757/status" pid=757 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=122 ouid=
Jan 11 09:37:15 irregular-apocalypse audit[757]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=757 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=
Jan 11 09:37:15 irregular-apocalypse audit[757]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/757/status" pid=757 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=122 ouid=
Jan 11 09:37:15 irregular-apocalypse kernel: audit: type=1400 audit(1515627435.055:544): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/757/status" pid=757 comm="mysqld" requested_mask
Jan 11 09:37:15 irregular-apocalypse kernel: audit: type=1400 audit(1515627435.055:545): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=757 comm="mysqld" reque
Jan 11 09:37:15 irregular-apocalypse kernel: audit: type=1400 audit(1515627435.055:546): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/757/status" pid=757 comm="mysqld" requested_mask
Jan 11 09:37:16 irregular-apocalypse systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
我研究了 apparmor 错误并得出结论,它们不是导致我的问题的原因,因为如果我删除default_time_zone
配置项并启动服务器,也会出现相同的错误:
Jan 11 09:40:14 irregular-apocalypse systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mysql.service has begun starting up.
Jan 11 09:40:14 irregular-apocalypse audit[1516]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/1516/status" pid=1516 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=122 ou
Jan 11 09:40:14 irregular-apocalypse audit[1516]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=1516 comm="mysqld" requested_mask="r" denied_mask="r" fsui
Jan 11 09:40:14 irregular-apocalypse audit[1516]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/1516/status" pid=1516 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=122 ou
Jan 11 09:40:14 irregular-apocalypse kernel: audit: type=1400 audit(1515627614.793:562): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/1516/status" pid=1516 comm="mysqld" requested_ma
Jan 11 09:40:14 irregular-apocalypse kernel: audit: type=1400 audit(1515627614.793:563): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=1516 comm="mysqld" requ
Jan 11 09:40:14 irregular-apocalypse kernel: audit: type=1400 audit(1515627614.793:564): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/proc/1516/status" pid=1516 comm="mysqld" requested_ma
Jan 11 09:40:15 irregular-apocalypse systemd[1]: Started MySQL Community Server.
-- Subject: Unit mysql.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit mysql.service has finished starting up.
--
-- The start-up result is done.
我拥有的唯一文件/var/log/mysql
是error.log
,它不包含与启动失败相关的任何内容。我在我的数据目录 ( ) 中找不到任何 *.err 或 *.log 文件/var/lib/mysql
。
我已多次清除并重新安装 mysql-server,但没有任何效果。
我的问题实际上有两个:
这是为 MySQL 设置 default_time_zone 的正确方法吗?如果不是,我该怎么做?
如果问题 1 的答案无法解决我的问题,我该如何找出导致 MySQL 启动错误的原因?
操作系统:Ubuntu 桌面 17.10
MySQL:5.7
答案1
所以问题出在我没有填充时区表。运行此命令解决了我的问题:
mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root -p mysql