MySQL Shell 8.0  /  MySQL Shell Logging and Debug  /  MySQL Shell SQL Logging

12.4 MySQL Shell SQL Logging

From MySQL Shell 8.0.30, you can log all SQL statements executed by MySQL Shell commands or utilities to the MySQL Shell log file.

Note

logSql replaces dba.logSql if dba.logSql is disabled, logSql takes precedence. However, if dba.logSql is enabled, it takes precedence over logSql, but only for log messages in the dba.* context.

The application log level must be set to at least INFO (5), for these messages to be written to the MySQL Shell log.

SQL Logging Options

MySQL Shell SQL logging can be enabled, disabled, or altered in one of the following ways:

  • Command line: --log-sql=logOption in your MySQL Shell startup command.

  • MySQL Shell configuration options: shell.options['logSql']='logOption' during your MySQL Shell session.

The following options are available:

off

No MySQL Shell SQL statements are logged.

error

(Default) only MySQL Shell failed SQL statements with are logged.

on

All MySQL Shell SQL statements are logged, except those which match the ignore pattern defined in logSql.ignorePattern and logSql.ignorePatternUnsafe. See Filtering SQL Logging for more information.

all

All MySQL Shell SQL statements are logged, except those which match the ignore pattern defined in the logSql.ignorePatternUnsafe]. See Filtering SQL Logging for more information.

unfiltered

All MySQL Shell SQL statements are logged, no filtering is performed.

Filtering SQL Logging

The log is filtered using a colon-separated list of glob patterns. The following options are available:

  • logSql.ignorePattern: This option defines a colon-separated list of statement patterns to filter out. Default value is *SELECT*:*SHOW*.

  • logSql.ignorePatternUnsafe: This option defines a colon-separated list of statement patterns to filter out. Default value is *IDENTIFIED*:*PASSWORD*.

For information on working with shell.options, see Section 13.4, “Configuring MySQL Shell Options”.

Log Format

The log messages use the following format:

Date&Time: LogLevel: LogContext: tid= : SQL:
Date&Time

Date and time of the log message.

LogLevel

The log level. For more information on log levels, seeTable 12.1, “Logging levels in MySQL Shell”.

All successful SQL statements and error messages for unsuccessful statements are logged with INFO log level.

LogContext

The origin of the log message. Can be one of the following values:

  • main: base MySQL Shell context.

  • sql: SQL mode context.

  • js: JavaScript mode context.

  • py: Python mode context.

  • object.method: Global object method context. For example, Dba.createCluster or Cluster.status.

tid

The MySQL thread ID.

SQL

The logged SQL statement or error message.

The following example shows an SQL INFO message with a Dba.deploySandboxInstance context:

        2022-06-17 15:06:00: Info: Dba.deploySandboxInstance: tid=9: SQL: SET SESSION `autocommit` = 1