EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Login
Home Software Development Software Development Tutorials MariaDB Tutorial MariaDB Logs

MariaDB Logs

Updated April 12, 2023

MariaDB Logs

Definition of MariaDB Logs

MariaDB server uses a different log file such as error log file, binary log file, general query log, and slow query log files. As per our requirement, we can change the status of log files that enable and disable log files. The main purpose of a log file is that to store different data during the different operation, for example, if we consider error log file, the error log file is used to store the critical error occurred during the MariaDB server operation, table corruption and start and stop information. If we consider SQL errors it can also be used in different log files by using the SQL_ERROR plugin.

ADVERTISEMENT
Popular Course in this category
MARIADB Course Bundle - 5 Courses in 1

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

set global log type = value;

Explanation:

In the above syntax, we use the set global command, here log type means log file name and value means 1 or 0 that we need to set.

show global variables like 'log file name';

Explanation:

In the above example, we use show global variable command to see the log file, here we use log file name means you can use any log file name to see the details of a specified log file.

How Logs works in MariaDB?

Now let’s see how logs work in MariaDB as follows. Basically, MariaDB uses different log files let’s see one by one.

1. Error Log

In this log file, it contains all records of critical errors that occurred during the different operations of the server like a corrupted table, which service start and stop information. SQL error is also used in a separate log file using the SQL_ERROR_LOG plugin.

Now let’s see how we can write error logs to a file.

When we need to configure an error log to write a log file at that time we must need to set the log_error system variable. By using a system variable we can configure a specific file name, if we don’t use specified file name to the configuration at that time log will be written to hostname.err file in the directory and this is by default directory.

We can set the log_error system variable by using the server option group. For example to write error log in by default log file that is ${hostname}.err. We need to configure the following line as follows.

[mariadb]
……
log_error

If we need to configure a specific file name as a log_error system variable and this file doesn’t have an absolute path then it uses a relative path to the datadir directory. Now see the following example of a configured error log that would be written to the mariadb.err file from datadir directory.

[mariadb]
……
log_error = mariadb.err

See in above example path is a relative path but some it also uses absolute path. For example:

[mariadb]
……
log_error = \C:\Program Files (x86)\MariaDB 10.5\include\mysql\mariadb.err.

We can also use another path to configure the error log file that is to set log – basename option which is configured by MariaDB.

2. General Query Log

The general query log file is used to store all details about every SQL query received from the client-side as well as all connected and disconnected client information.

Now see how we can enable the general query log as follows.

The general query log is to be disabled by default. To enable the general log file then we need to set the general_log system variable to 1 and it also changes dynamically.

For Example: 

set global general_log = 1;

We can also set general_log file by using the server option group. For example:

[mariadb]
………..
general_log

Now see how we can configure the general query log file name as follows.

For configuration purposes, we use a default data-dir directory that is ${hostname}.log and a general_log_file system variable can be changed dynamically. For example:

set global general_log_file = 'mariadb.log';

We can also set the general_log_file by using the server option group from the file option. for example:

[mariadb]
……………..
general_log
general_log_file = mariadb.log

In the above example, we use a relative path but it also uses an absolute path.

Let’s see how we select the destination file for the general query log as follows.

It can be written to a file on disk or it can be written on the general_log table in the MySQL database. For selecting the destination file for output we use log_output system variable.

set global log_output = 'specified file name';

3. Slow Query Log

In this type of log file, the slow query log file is used to store records of SQL queries that take a long time to execute. In this type of query, the password then slow query log also contains the password.

Now let’s see how we can enable the slow query log as follows.

To enable the slow query log file we use the slow_query_log system variable that means we set the global variable is 1 as follows.

set global slow_query_log = 1

We can also set it by using the server option group from the file option.

Configuration of the slow query log by using the file name as follows.

We can configure the slow query log by using a filename that means we need to set a slow_query_log_file system variable by using the relative path as well as an absolute path, same like the above-mentioned types.

4. Binary Log

In this type, we stored all records of the database and structure as well as how each query takes a long time to execute.

Examples

Let’s see the different examples of MariaDB log as follows.

Suppose we need to show log error at that time we use the following statement.

show global variables like 'log_error';

Explanation:

In the above example, we use the show variable command to show log error. The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB Logs 1

Now how we can set the global general log by using the following statement.

set global general_log = 1;

Explanation:

The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB Logs 2

In this way, we can set all log types as per requirement.

Conclusion

We hope from this article you have understood about the MariaDB Logs. From this article, we have learned the basic syntax of MariaDB Logs and we also see different examples of MariaDB Logs. From this article, we learned how and when we use MariaDB Logs.

Recommended Articles

We hope that this EDUCBA information on “MariaDB Logs” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. MariaDB Grant All Privileges
  2. MariaDB MaxScale
  3. MariaDB Foreign Key
  4. MariaDB Commands
ADVERTISEMENT
MICROSOFT POWER BI Course Bundle - 8 Courses in 1
34+ Hours of HD Videos
8 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
CYBER SECURITY & ETHICAL HACKING Course Bundle - 13 Courses in 1 | 3 Mock Tests
64+ Hours of HD Videos
13 Courses
3 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
63+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
KALI LINUX Course Bundle - 6 Courses in 1
20+ Hours of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW