无法在更新后重新启动mariadb

我刚更新了mariadbarch-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 

my.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 

OS详细信息:

 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 

这似乎是一个AppArmor相关的问题。 尝试禁用AppArmor颁发systemctl stop apparmor.service并重新启动MariaDB

无论如何,正如已经build议的, /home是MariaDB / MySQL的错误地方。 请将您的数据目录移到/var/lib

你正在使用一个错误的数据目录。 你不应该在/home下存储MySQL / MariaDB的数据。

出于安全原因,数据库不允许访问用户主目录。 为了做到这一点,systemd在一个容器中运行MariaDB,这个容器不能访问/home

datadir的“标准”位置是/var/lib/mysql 。 将datadir更改为正确的值,然后重试。

您可以使用-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 

由于未知的原因,我通过删除/var/lib/mysql并创build从var/lib/mysql/home/mysql的软链接来工作。 在/usr/lib/systemd/system/mariadb.service中不需要任何修改。 我不明白为什么它的作品。 也许有人可以解释它。