Opensuse

將 datadir 行添加到 my.cnf 文件後無法重新啟動 MariaDB

  • November 10, 2021

在將以下行添加到

$$ mysqld $$my.cnf 的部分:

datadir = /home/mysql

它不會重新啟動。這可能是權限問題。這是保存我所有 SQL 數據的目錄。這是 systemctl status mysql.service 顯示的內容

● mariadb.service - MariaDB database server
  Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since Wed 2021-11-10 08:33:00 CST; 36s ago
    Docs: man:mysqld(8)
          https://mariadb.com/kb/en/library/systemd/
 Process: 14438 ExecStart=/usr/lib/mysql/mysql-systemd-helper start (code=exited, status=1/FAILURE)
 Process: 14425 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper upgrade (code=exited, status=0/SUCCESS)
 Process: 14412 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper install (code=exited, status=0/SUCCESS)
Main PID: 14438 (code=exited, status=1/FAILURE)
  Status: "MariaDB server is down"

Nov 10 08:33:00 law-amp3 mysql-systemd-helper[14438]: 2021-11-10  8:33:00 0 [Note] /usr/sbin/mysqld (mysqld 10.4.17-MariaDB-log) starting as process 14438 ...
Nov 10 08:33:00 law-amp3 mysql-systemd-helper[14438]: 2021-11-10  8:33:00 0 [Warning] Could not increase number of max_open_files to more than 1024 (request: 32214)
Nov 10 08:33:00 law-amp3 mysql-systemd-helper[14438]: 2021-11-10  8:33:00 0 [Warning] Changed limits: max_open_files: 1024  max_connections: 151 (was 151)  table_cache: 421 (was 2000)
Nov 10 08:33:00 law-amp3 mysql-systemd-helper[14438]: 2021-11-10  8:33:00 0 [Warning] Can't create test file /home/mysql/law-amp3.lower-test
Nov 10 08:33:00 law-amp3 mysql-systemd-helper[14438]: [87B blob data]
Nov 10 08:33:00 law-amp3 mysql-systemd-helper[14438]: 2021-11-10  8:33:00 0 [ERROR] Aborting
Nov 10 08:33:00 law-amp3 systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Nov 10 08:33:00 law-amp3 systemd[1]: Failed to start MariaDB database server.
Nov 10 08:33:00 law-amp3 systemd[1]: mariadb.service: Unit entered failed state.
Nov 10 08:33:00 law-amp3 systemd[1]: mariadb.service: Failed with result 'exit-code'.

聽起來像是權限問題。確保目錄的所有者是 mysql。例如

chown --reference=/var/lib/mysql /home/mysql
chmod --reference=/var/lib/mysql /new/dir/for/mysql

編輯:

查看服務文件是否有 ProtectHome

vi /usr/lib/systemd/system/mariadb.service

將 ProtectHome=true 更改為 ProtectHome= false

保存文件

systemctl daemon-reload

重啟 mariadb

引用自:https://unix.stackexchange.com/questions/676899