为什么 MariaDB 拒绝启动?

为什么 MariaDB 拒绝启动?

MariaDB 拒绝启动并出现以下错误:

Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 "Permission denied")

我认为可能是某个地方的权限错误。我该如何修复它?

我已经尝试删除undo001undo003undo002ib_logfile0ibdata1也失败了:

chown mysql:mysql /var/run/mysqld

只是不确定要运行什么命令。

日志:

░░ The job identifier is 4160.
Mar 08 16:15:47 jammy-bare mariadbd[3836]: /usr/sbin/mariadbd: One can only use the --user switch if running as root
Mar 08 16:15:47 jammy-bare mariadbd[3836]: 2024-03-08 16:15:47 0 [Note] Starting MariaDB 11.3.2-MariaDB-1:11.3.2+maria~ubu2204 source revision 068a6819eb63bcb01fdfa037c9bf3bf63c33ee42 as process 3836
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: !!! innodb_force_recovery is set to 3 !!!
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Number of transaction pools: 1
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Completed initialization of buffer pool
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: File system buffers for log disabled (block size=512 bytes)
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=17990
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: End of log at LSN=37358
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: To recover: 146 pages
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Opened 3 undo tablespaces
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: 128 rollback segments in 3 undo tablespaces are active.
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1"
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: log sequence number 37358; transaction id 3
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] Plugin 'FEEDBACK' is disabled.
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] Plugin 'wsrep-provider' is disabled.
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] InnoDB: Buffer pool(s) load completed at 240308 16:15:48
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] Recovering after a crash using tc.log
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] Starting table crash recovery...
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] Crash table recovery finished.
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [Note] Server socket created on IP: '0.0.0.0'.
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [ERROR] mariadbd: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 "Permission denied")
Mar 08 16:15:48 jammy-bare mariadbd[3836]: 2024-03-08 16:15:48 0 [ERROR] Can't start server: can't create PID file: Permission denied
Mar 08 16:15:48 jammy-bare systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ An ExecStart= process belonging to unit mariadb.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Mar 08 16:15:48 jammy-bare systemd[1]: mariadb.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ The unit mariadb.service has entered the 'failed' state with result 'exit-code'.
Mar 08 16:15:48 jammy-bare systemd[1]: Failed to start MariaDB 11.3.2 database server.
░░ Subject: A start job for unit mariadb.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit mariadb.service has finished with a failure.
░░ 
░░ The job identifier is 4160 and the job result is failed.

我的cnf

  GNU nano 6.2                                                                                     /etc/mysql/my.cnf                                                                                              
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/

#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

[mysqld]
bind-address = 0.0.0.0
user=root
pid-file     = /var/run/mysqld/mysqld.pid
socket       = /var/run/mysqld/mysqld.sock
port         = 3306                                                                                                                                                                                              >

[client]
port         = 3306
socket       = /var/run/mysqld/mysqld.sock

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8


[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8

innodb_force_recovery = 3

答案1

错误是:

Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 "Permission denied")

你所做的其他事情(很可能是基于在网上找到的随机内容)都没什么用。这些基本上都是用不相关的“技巧”解决问题的绝望尝试。始终关注给出的错误;它总能找到解决方案。

针对错误,我建议你做两件事:

  1. 运行此命令来创建占位mysqld.pid文件:
    sudo touch /var/run/mysqld/mysqld.pid
    
  2. 然后运行此命令将所有者和组设置为mysql;您可能在技术上正在运行 MariaDB,但它最终与 MySQL 的工作方式相同:
    sudo chown mysql:mysql -R /var/run/mysqld
    

然后尝试再次启动 MariaDB。

相关内容