Skip to content
Frédéric Descamps edited this page Nov 6, 2022 · 5 revisions

logs

NAME
      logs - MySQL Logs Utility.

DESCRIPTION
      A collection of tools to manage and get information related to the logs
      of MySQL Database Server

Methods:

getErrorLogByTime

logs.getErrorLogByTime([start][, limit][, type][, subsystem][,
      format][, session])

Get Errog Log from a specific time

  • start: String. Start time from when you retrieve errors
  • limit: Integer. The amount of lines to display. 0 means no limit. Default: 0.
  • type: String. The type of error entries. Valid values are 'all', 'system', 'error', 'warning' and 'note'. Default is 'all'.
  • subsystem: String. Filter the entries to only get this specific subsystem. Default is 'all'.
  • format: String. One of table, tabbed, vertical, json, ndjson, json/raw, json/array, json/pretty or flat. Flat is like an error log with colors. Default is table.
  • session: Object. The optional session object used to query the database. If omitted the MySQL Shell's current session will be used.
 JS  logs.getErrorLogByTime("3 years ago", 10)
GETTING LOGS FROM 2018-02-12 00:00:00:
Warning: the first log entry available is from 2019-02-07 11:07:13.122633
+----------------------------+-----------+---------+------------+-----------+--------------------------------------------------------------------------------------------------------------------------------------------+
| LOGGED                     | THREAD_ID | PRIO    | ERROR_CODE | SUBSYSTEM | DATA                                                                                                                                       |
+----------------------------+-----------+---------+------------+-----------+--------------------------------------------------------------------------------------------------------------------------------------------+
| 2019-02-07 11:07:13.122633 |         0 | System  | MY-013169  | Server    | /usr/sbin/mysqld (mysqld 8.0.15) initializing of server in progress as process 30772                                                       |
| 2019-02-07 11:07:28.313296 |         5 | Warning | MY-010453  | Server    | root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.                         |
| 2019-02-07 11:07:35.575291 |         0 | System  | MY-013170  | Server    | /usr/sbin/mysqld (mysqld 8.0.15) initializing of server has completed                                                                      |
| 2019-02-07 11:08:22.40286  |         0 | System  | MY-010116  | Server    | /usr/sbin/mysqld (mysqld 8.0.15) starting as process 30863                                                                                 |
| 2019-02-07 11:08:24.190491 |         0 | Warning | MY-010068  | Server    | CA certificate ca.pem is self signed.                                                                                                      |
| 2019-02-07 11:08:24.221343 |         0 | System  | MY-010931  | Server    | /usr/sbin/mysqld: ready for connections. Version: '8.0.15'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL. |
| 2019-02-07 11:08:24.441413 |         0 | System  | MY-011323  | Server    | X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060                                       |
| 2019-02-09 23:58:15.92052  |         0 | System  | MY-010910  | Server    | /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.15)  MySQL Community Server - GPL.                                                         |
| 2019-02-14 11:49:39.44305  |         0 | System  | MY-010116  | Server    | /usr/sbin/mysqld (mysqld 8.0.15) starting as process 1931                                                                                  |
| 2019-02-14 11:49:47.668764 |         0 | Warning | MY-010068  | Server    | CA certificate ca.pem is self signed.                                                                                                      |
+----------------------------+-----------+---------+------------+-----------+--------------------------------------------------------------------------------------------------------------------------------------------+

getErrorLogConfig

getErrorLogConfig([session])

Prints the values of the configuration variables related to the Error Log

 JS  logs.getErrorLogConfig()
MySQL Error Log Settings:
-------------------------
log_error                  : /home/fred/sandboxes/group_sp_msb_8_0_23/node1/data/msandbox.err                                                        
log_error_services         : log_filter_internal; log_sink_internal                                                                                  
log_error_suppression_list :                                                                                                                         
log_error_verbosity        : 2   

setErrorLogVersbosity

Set the values of Error Log Verbosity.

setErrorLogVersbosity([value][, persist][, session])
  • value: Integer. The optional value of the verbosity (1=ERROR, 2=ERROR, WARNING, 3=ERROR, WARNING, INFORMATION). The default is to set it to 3.
  • persist: Bool. Persist the change. Default: false.
  • session: Object. The optional session object used to query the database. If omitted the MySQL Shell's current session will be used.
 JS  logs.setErrorLogVersbosity()
Error Log Verbosity is now set to 3

showErrorLog

Display the Errog Log lines.

showErrorLog([limit][, type][, subsystem][, format][, session])
  • limit: Integer. The amount of lines to display. 0 means no limit. Default: 10.
  • type: String. The type of error entries. Valid values are 'all', 'system', 'error', 'warning' and 'note'. Default is 'all'.
  • subsystem: String. Filter the entries to only get this specific subsystem. Default is 'all'.
  • format: String. One of table, tabbed, vertical, json, ndjson, json/raw, json/array, json/pretty or flat. Flat is like an error log with colors. Default is table.
  • session: Object. The optional session object used to query the database. If omitted the MySQL Shell's current session will be used.
 JS  logs.showErrorLog(3,'all','all','vertical')
*************************** 1. row ***************************
    LOGGED: 2021-02-03 16:56:31.184002
 THREAD_ID: 0
      PRIO: System
ERROR_CODE: MY-013602
 SUBSYSTEM: Server
      DATA: Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
*************************** 2. row ***************************
    LOGGED: 2021-02-03 16:56:31.363887
 THREAD_ID: 0
      PRIO: Warning
ERROR_CODE: MY-013368
 SUBSYSTEM: Server
      DATA: At least one partial revoke exists on a database. Turning ON the system variable '@@partial_revokes'.
*************************** 3. row ***************************
    LOGGED: 2021-02-03 16:56:31.434949
 THREAD_ID: 0
      PRIO: System
ERROR_CODE: MY-010931
 SUBSYSTEM: Server
      DATA: /usr/sbin/mysqld: ready for connections. Version: '8.0.23'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL

Try the 'flat' format ;-)

tailErrorLog

Tail the Errog Log lines.

logs.tailErrorLog([limit][, type][, subsystem][, refresh][, session])
  • limit: Integer. The amount of lines to display when starting the tail. 0 means no limit. Default: 10.
  • type: String. The type of error entries. Valid values are 'all', 'system', 'error', 'warning' and 'note'. Default is 'all'.
  • subsystem: String. Filter the entries to only get this specific subsystem. Default is 'all'.
  • refresh: Integer. amount of seconds to refresh the tail output. Default is 1.
  • session: Object. The optional session object used to query the database. If omitted the MySQL Shell's current session will be used.

setupForSlowQueryLog

Enables instruments for fetching the required info to generate a slow query log file from Performance_Schema tables.

logs.setupForSlowQueryLog([enable][, session])            
  • enable: Bool - Enable the events history long instrumentation. (default: True).
  • session: Object - The optional session object used to query the database. If omitted the MySQL Shell's current session will be used.
 JS > logs.setupForSlowQueryLog()
The consumers for 'events_statements_history' are not enabled,
do you want to enabled them now ? (y/N) : y
Everything required is enabled

 JS > logs.setupForSlowQueryLog(false)
Required instruments are now disabled !

generateSlowQueryLog

Generates a slow query log file from Performance_Schema tables.

logs.generateSlowQueryLog([truncate][, session])
  • truncate: Bool - Truncate the Performance_Schema tables after retrieving the data (default: False).
  • session: Object - The optional session object used to query the database. If omitted the MySQL Shell's current session will be use
 JS > logs.generateSlowQueryLog()
Where do you want to store the slow query log ? (slow_dell_202211062205.log): 
Slow query log with 133 entries generated as slow_dell_202211062205.log

The output is like this:

# Time: 2022-11-06T15:44:50.009304Z
# User@Host: n/a [] @ n/a []  Id: 55
# Query_time: 0.000404  Lock_time: 0.000005  Rows_sent: 8  Rows_examined: 8  Row
s_affected: 0
# Bytes_sent: n/a  Tmp_tables: 0  Tmp_disk_tables: 0  Tmp_table_sizes: n/a
# Full_scan: yes  Full_join: no  Tmp_table: no  Tmp_table_on_disk: no
# Merge_passes: 0 Execution_engine: PRIMARY
# No_index_used: yes  Cpu_time: 0   Max_memory: 1725778
SET timestamp=1667745890;
select * from t1;
Clone this wiki locally