How to read the MySQL Audit.log file in a SQL table?

Posted on

Question :

I tried to read the Audit.log file of the MySQL Enterprise using a table or other more friendly format and easy to access and understand, but the xml format with which it is written has an irregular structure:

   <TIMESTAMP>2019-02-17T12:53:23 UTC</TIMESTAMP>
   <STARTUP_OPTIONS>./mysqld --basedir=/MYSQL_HOME/mysql</STARTUP_OPTIONS>

   <TIMESTAMP>2019-02-19T02:22:23 UTC</TIMESTAMP>

   <TIMESTAMP>2019-02-19T02:22:23 UTC</TIMESTAMP>
   <USER>flopez[nbryan] @  []</USER>
   <SQLTEXT>/*!40101 set @@session.wait_timeout=28800 */</SQLTEXT>

As you can see, the same tags are not always generated, so I have not been able to format it to a table from the SQL Server (there is a lot of information on how to read xml formats using sql). I wanted to know if there is another way, maybe from the same MySQL, although it is very difficult to find something of this manager in relation to other solutions.

Any help or idea would be very helpful.

Thank you.

Answer :

In this page you find information about Audit.log:

Audit Log File Reading
Audit Log can store log files as the XML or JSON format, depending on the specified output format. When the JSON logging is enabled, we can read events using the provided audit_log_read() UDF.

  "timestamp": "2018-05-24 23:15:07",
  "id": 0,
  "class": "connection",
  "event": "connect",
  "connection_id": 12,
  "account": { "user": "user",
               "host": "localhost" },
  "login": { "user": "user",
             "os": "",
             "ip": "::1",
             "proxy": "" },
  "connection_data": { "connection_type": "tcp/ip",
                       "status": 0,
                       "db": "bank_db" } }

Leave a Reply

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