MySQL have the nice feature, which helps to write the error log with JSON format . This can be achieved through the MySQL components . In this blog, I am going to show the complete walkthrough involved in this process .
What is MySQL component ?
from MySQL document ,
MySQL Server includes a component-based infrastructure for extending server capabilities. A component provides services that are available to the server and other components. (With respect to service use, the server is a component, equal to other components.) Components interact with each other only through the services they provide.
Link : https://dev.mysql.com/doc/refman/8.0/en/server-components.html
How to enable the JSON logging ?
Step 1 : ( Installing the component ) :
First step, we need to install the component “component_log_sink_json” .

cmd :
install component ‘file://component_log_sink_json’;
select * from mysql.component where component_urn like ‘%json%’\G
There is a table “mysql.component” , which will helps to obtain the status of the MySQL components .
Step 2 : ( Enabling the JSON service ) :
There are few services, which helps to design the error log format. The services based on the filter or sink . The variable “log_error_services” will helps to enable the required services .
Available services :
- log_filter_internal ( filter )
- log_filter_dragnet ( filter )
- log_sink_internal ( sink )
- log_sink_json ( sink )
- log_sink_syseventlog ( sink )
- log_sink_test ( sink )
For our purpose , I am going to enable the services “log_filter_internal” and “log_sink_json”
log_filter_interval : Implements filtering based on log event priority and error code, in combination with the log_error_verbosity and log_error_suppression_list system variable
log_sink_json : Implements the JSON logging in error log

cmd :
set global log_error_services = ‘log_filter_internal; log_sink_json’;
From the above screenshot, you can see the new file ( mysql.err.00.json ) was created , when I enabled the JSON service .
I have manually created a error log event for testing purpose ( by executing the wrong command ) ,

Yes, it is working well !!
Make sure to have the variable ( log_error_services) entry in the MySQL configuration file ( my.cnf ) as well . You can also use the SET PERSIST .
Note : The log directory should have the proper privileges .
How to uninstall the JSON component ?
You cannot simply uninstall the component by using the UNINSTALL COMPONENT command . You need to first remove the JSON service from the variable “log_error_services” . Then only the mysqld will allow you to perform the UNINSTALL COMPONENT command .

cmd :
uninstall component ‘file://component_log_sink_json’;
set global log_error_services=’log_filter_internal; log_sink_internal’;
Conclusion :
MySQL ERROR log will not contain any additional information with JSON format . But, you will have the name of each columns ( Time : xxxxxx , err_code : xxxx ) . And, the view is better . Hope this blog will helps to someone who loves JSON . I will coup with my next blog as much as possible .
Thanks !!!