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

Published on October 26, 2020 55 sec read

HIRE US 🖐
We're available to do freelance project. Take a look at our services!

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

Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.

Follow

Leave a Reply

Your email address will not be published. Required fields are marked *