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 replacesdba.logSql ifdba.logSql is disabled,logSql takes precedence. However, ifdba.logSql is enabled, it takes precedence overlogSql, but only for log messages in thedba.* context.

The application log level must be set to at leastINFO (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 inlogSql.ignorePattern andlogSql.ignorePatternUnsafe. SeeFiltering SQL Logging for more information.

all

All MySQL Shell SQL statements are logged, except those which match the ignore pattern defined in thelogSql.ignorePatternUnsafe]. SeeFiltering 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 withshell.options, seeSection 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 withINFO 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 orCluster.status.

tid

The MySQL thread ID.

SQL

The logged SQL statement or error message.

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

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