How to Add MariaDB Error Log File on CentOS 7/8

Hello server administrator, in this article I’m going to share how to create MariaBD error log flie on CentOS. I’m testing on CentOS 8. Let’s start:

Table of Contents

  1. Check Log File
  2. Create Log File
  3. See Error Logs & Reset

Check Log File

We can see log file in my.cnf file like:

cat /etc/my.cnf

We can also find log file using:

# login to mysql
mysql -u root -p
# now see log file location
show variables like '%log_erro%';

If you see like below image, you need to create error log file:

MariaDB [(none)]> show variables like '%log_erro%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_error     |       |
+---------------+-------+

Create Log File

Open my.cnf file and add this code:

[mysqld_safe]
log_error=/var/log/mariadb/error.log

[mysqld]
log_error=/var/log/mariadb/error.log

After that, restart mariadb service:

systemctl restart maridb

Now try to find error log file:

# login to mysql
mysql -u root -p
# now see log file location
show variables like '%log_erro%';

Output:

MariaDB [(none)]> show variables like '%log_erro%';
+---------------+----------------------------+
| Variable_name | Value                      |
+---------------+----------------------------+
| log_error     | /var/log/mariadb/error.log |
+---------------+----------------------------+

See Error Logs & Reset

We’ve added error log file. Now let’s check error logs by using this command:

sudo tail -f /var/log/mariadb/error.log

Great..! We’re seeing error logs of MariaDB. To reset or make the log file empty, just run this command:

sudo truncate -s 0 /var/log/mariadb/error.log

That’s it. Thanks for reading.


Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.