我刚刚更新mariadb
到 中的最新版本arch-linux
。我的数据库文件夹在 中/home/mysql
。突然间,我无法使用 重新启动它systemctl restart mysqld
。以下是错误日志:
-- Unit mariadb.service has begun starting up.
Jul 28 00:25:20 tao mysqld[8523]: 2016-07-28 0:25:20 140554735999040 [Note] /usr/sbin/mysqld (mysqld 10.1.16-MariaDB)
Jul 28 00:25:20 tao mysqld[8523]: 2016-07-28 0:25:20 140554735999040 [Warning] Can't create test file /home/mysql/tao
Jul 28 00:25:20 tao mysqld[8523]: [87B blob data]
Jul 28 00:25:20 tao mysqld[8523]: 2016-07-28 0:25:20 140554735999040 [ERROR] Aborting
Jul 28 00:25:20 tao systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Jul 28 00:25:20 tao systemd[1]: Failed to start MariaDB database server.
-- Subject: Unit mariadb.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mariadb.service has failed.
--
-- The result is failed.
Jul 28 00:25:20 tao systemd[1]: mariadb.service: Unit entered failed state.
Jul 28 00:25:20 tao systemd[1]: mariadb.service: Failed with result 'exit-code'.
Jul 28 00:25:20 tao sudo[8405]: pam_unix(sudo:session): session closed for user root
这可能是致命的错误:
`Can't create test file /home/mysql/tao`
这和我的 db 文件夹位于主目录中有什么关系吗?我想知道发生了什么变化导致 mariadb 无法访问/home/mysql
。
/etc/systemd/system/mariadb.service 文件:
#
# /etc/systemd/system/mariadb.service
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Thanks to:
# Daniel Black
# Erkan Yanar
# David Strauss
# and probably others
[Unit]
Description=MariaDB database server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
##############################################################################
## Core requirements
##
Type=notify
# Setting this to true can break replication and the Type=notify settings
# See also bind-address mysqld option.
PrivateNetwork=false
##############################################################################
## Package maintainers
##
User=mysql
Group=mysql
# To allow memlock to be used as non-root user if set in configuration
CapabilityBoundingSet=CAP_IPC_LOCK
# Prevent writes to /usr, /boot, and /etc
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
# Prevent accessing /home, /root and /run/user
ProtectHome=true
# Execute pre and post scripts as root, otherwise it does it as User=
PermissionsStartOnly=true
# Perform automatic wsrep recovery. When server is started without wsrep,
# galera_recovery simply returns an empty string. In any case, however,
# the script is not expected to return with a non-zero status.
# It is always safe to unset _WSREP_START_POSITION environment variable.
ExecStartPre=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
ExecStartPre=/bin/sh -c "VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && \
systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1"
# Needed to create system tables etc.
# ExecStartPre=/usr/bin/mysql_install_db -u mysql
# Start main service
# MYSQLD_OPTS here is for users to set in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf
# Use the [service] section and Environment="MYSQLD_OPTS=...".
# This isn't a replacement for my.cnf.
# _WSREP_NEW_CLUSTER is for the exclusive use of the script galera_new_cluster
ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION --data-dir=/home/mysql
# Unset _WSREP_START_POSITION environment variable.
ExecStartPost=/bin/sh -c "systemctl unset-environment _WSREP_START_POSITION"
KillMode=process
KillSignal=SIGTERM
# Don't want to see an automated SIGKILL ever
SendSIGKILL=no
# Restart crashed server only, on-failure would also restart, for example, when
# my.cnf contains unknown option
Restart=on-abort
RestartSec=5s
UMask=007
##############################################################################
## USERs can override
##
##
## by creating a file in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf
## and adding/setting the following will override this file's settings.
# Useful options not previously available in [mysqld_safe]
# Kernels like killing mysqld when out of memory because its big.
# Lets temper that preference a little.
# OOMScoreAdjust=-600
# Explicitly start with high IO priority
# BlockIOWeight=1000
# If you don't use the /tmp directory for SELECT ... OUTFILE and
# LOAD DATA INFILE you can enable PrivateTmp=true for a little more security.
PrivateTmp=true
##
## Options previously available to be set via [mysqld_safe]
## that now needs to be set by systemd config files as mysqld_safe
## isn't executed.
##
# Number of files limit. previously [mysqld_safe] open-file-limit
LimitNOFILE=16364
# Maximium core size. previously [mysqld_safe] core-file-size
# LimitCore=
# Nice priority. previously [mysqld_safe] nice
# Nice=-5
# Timezone. previously [mysqld_safe] timezone
# Environment="TZ=UTC"
# Library substitutions. previously [mysqld_safe] malloc-lib with explict paths
# (in LD_LIBRARY_PATH) and library name (in LD_PRELOAD).
# Environment="LD_LIBRARY_PATH=/path1 /path2" "LD_PRELOAD=
# Flush caches. previously [mysqld_safe] flush-caches=1
# ExecStartPre=sync
# ExecStartPre=sysctl -q -w vm.drop_caches=3
# numa-interleave=1 equalivant
# Change ExecStart=numactl --interleave=all /usr/sbin/mysqld......
# crash-script equalivent
# FailureAction=
/home.mysql 文件夹权限
drwxr-xr-x 6 mysql mysql 12288 Jul 27 19:34 mysql
我的CF
[client]
port = 3306
socket = /run/mysqld/mysqld.sock
[mysqld]
init_connect = 'SET collation_connection = utf8_general_ci,NAMES utf8'
collation_server = utf8_general_ci
#character_set_client = utf8
skip-character-set-client-handshake
character_set_server = utf8
port = 3306
socket = /run/mysqld/mysqld.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
bind-address = 127.0.0.1
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
datadir = /home/mysql
innodb_data_home_dir = /home/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
操作系统详细信息:
Linux version 4.6.4-1-ARCH (builduser@tobias) (gcc version 6.1.1 20160707 (GCC) ) #1 SMP PREEMPT Mon Jul 11 19:12:32 CEST 2016
答案1
这似乎是与 AppArmor 相关的问题。尝试禁用 AppArmor 发行systemctl stop apparmor.service
并重新启动 MariaDB
无论如何,正如已经建议的那样,/home
这是 MariaDB/MySQL 的错误位置。请将您的数据目录移至/var/lib
答案2
您使用的 目录错误datadir
。您应该不是将 MySQL/MariaDB 的数据存储在 下/home
。
出于安全原因,数据库不允许访问用户主目录。为了实现这一点,systemd 在无法访问的容器中运行 MariaDB /home
。
datadir 的“标准”位置是/var/lib/mysql
。将 datadir 更改为正确的值,然后重试。
答案3
您可以使用 -o bind 将 /home/mysql 挂载到 /var/lib/mysql
mount -o bind /home/mysql /var/lib/mysql
在 /etc/fstab 中:
/home/mysql /var/lib/mysql none rw,bind 0 0
答案4
由于未知原因,我通过删除并创建从到 的 /var/lib/mysql
软链接使其工作。 /usr/lib/systemd/system/mariadb.service 中无需任何修改。我不明白为什么它就这样工作。也许有人可以解释一下。var/lib/mysql
/home/mysql