Why is MariaDB refusing to start

linuxmariadbMySQL

MariaDB refused to start with this error:

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

I think it may be a permissions error somewhere,. How would I fix it?

I have already tried deleting undo001, undo003 and undo002 and ib_logfile0 and ibdata1. Also failed:

chown mysql:mysql /var/run/mysqld

Just unsure what commands to run.

Logs:

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

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

Best Answer

The error is:

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

All the other stuff you did — most likely based on random stuff found on the web — is not very useful. Those are basically desperate attempts to resolve an issue with unrelated “tricks.” Always focus on the error given; it will always lead to a solution.

Focusing on the error, I suggest you do two things:

  1. Run this to create a placeholder mysqld.pid file:
    sudo touch /var/run/mysqld/mysqld.pid
    
  2. Then run this command to set owner and group to mysql; you might be technically running MariaDB, but it is ultimately and MySQL work-alike:
    sudo chown mysql:mysql -R /var/run/mysqld
    

Then try to start MariaDB again.

Related Question