You can log all SQL statements executed by MySQL Shell commands or utilities to the MySQL Shell log file.
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.
MySQL Shell SQL logging can be enabled, disabled, or altered in one of the following ways:
Command line:
--log-sql=
in your MySQL Shell startup command.logOption
-
MySQL Shell configuration options:
shell.options['logSql']='
during your MySQL Shell session.logOption
'
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
andlogSql.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.
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”.
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
orCluster.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