The MySQL and MariaDB error log is the fastest way to turn “it won’t start” into a real diagnosis, because startup, shutdown, crash recovery, and configuration complaints all land in one place.
The database daemon (mysqld or mariadbd) writes error messages to a destination controlled by server options such as log_error plus distribution packaging defaults. On many Linux systems using systemd, the service unit can capture stderr and store the same messages in systemd-journald instead of a traditional file under /var/log/.
Reading the error log commonly requires root or a privileged database account, and the contents can include internal paths, usernames, plugin names, and sometimes fragments of statements, so logs are best treated as sensitive. Rotated logs may appear as numbered siblings (for example, error.log.1) or compressed archives (for example, .gz), so older incidents may live outside the current file.
Steps to view the MySQL or MariaDB error log:
- Identify the running database container.
$ sudo docker ps --filter name=sg-mysql --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}' NAMES IMAGE STATUS sg-mysql mysql:8.0 Up 4 minutesOn systemd hosts, use
systemctl list-units --type=service --all 'mysql*' 'mariadb*' 'mysqld*'
to find the unit name.
- Read the error log destination from the running server via log_error.
$ sudo mysql --batch --skip-column-names --execute "SHOW VARIABLES LIKE 'log_error';" log_error stderr
Socket-auth installs often support sudo mysql, and password-based installs typically use mysql --user=root --password.
- Read datadir when log_error is a relative path.
$ sudo mysql --batch --skip-column-names --execute "SHOW VARIABLES LIKE 'datadir';" datadir /var/lib/mysql/
A log_error value like ./db1.err lives under datadir.
- Print the most recent error log entries when log_error=stderr.
$ sudo docker logs --tail 5 sg-mysql 2025-12-25T01:08:59.302807Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2025-12-25T01:08:59.302835Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 2025-12-25T01:08:59.303846Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory. 2025-12-25T01:08:59.311743Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock 2025-12-25T01:08:59.311782Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.44' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
Paste logs into tickets only after removing hostnames, usernames, internal paths, and any query text that should not leave the environment.
- Follow the error log stream while reproducing the issue.
$ sudo docker logs --tail 2 sg-mysql 2025-12-25T01:08:59.311743Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock 2025-12-25T01:08:59.311782Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.44' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
- Filter the log stream to recent entries when the log is noisy.
$ sudo docker logs --since 5m sg-mysql 2025-12-25T01:08:57.589059Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.44). 2025-12-25 01:08:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.44-1.el9 started. 2025-12-25 01:08:58+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2025-12-25 01:08:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.44-1.el9 started. '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock' 2025-12-25T01:08:59.151605Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead. ##### snipped #####
- Search common configuration paths for an explicit log_error setting when the destination is unclear.
$ sudo docker exec sg-mysql grep --recursive --line-number --extended-regexp '^[[:space:]]*(log_error|log-error)[[:space:]]*=' /etc/mysql 2>/dev/null No log_error entries found in /etc/mysql
Changing /etc/mysql/ or /etc/my.cnf/ does not move existing logs automatically, and a restart is usually required to apply a new destination.
- List rotated siblings of the error log when older entries are needed.
$ sudo docker exec sg-mysql ls -lh /var/log/mysql/error.log* ls: cannot access '/var/log/mysql/error.log*': No such file or directory
Use zless or zgrep for .gz logs to avoid manual decompression.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
