MySQL Client Logging

Let us understand about client logging with respect to MySQL. The mysql client can do different types of logging for statements that are executed, and it can be interactively −

UNIX - Logging

On Unix, mysql writes the statements to a history file. By default, this file is named as .mysql_history in the user’s home directory. To specify a different file name, the value of the MYSQL_HISTFILE environment variable has to be set.

If the --syslog option is given, mysql will write the statements to the system logging facility on all kinds of platforms. On Unix, this is known as syslog.

Windows - Logging

On Windows, it is known as the Windows Event Log. The destination where the logged messages appear is depends on the system. For example, on Linux, the destination is usually the /var/log/messages file.

How logging occurs?

Let us understand how logging occurs −

For every enabled logging destination, statement logging occurs as discussed below −

  • Statements are logged only when they are executed interactively. Statements are noninteractive when they are read from a file or a pipe. It is possible to suppress the operation of statement logging with the help of the --batch or --execute option.

  • Statements are ignored and not logged if they match a pattern present in the “ignore” list.

  • The mysql logs every non-ignored, non-empty statement line individually.

  • If a non-ignored statement spans over multiple lines, which doesn’t include the terminating delimiter, then mysql will concatenate the lines to form a complete statement, and maps the newlines to spaces, and logs in the result, along with a delimiter.

Updated on: 10-Mar-2021


Kickstart Your Career

Get certified by completing the course

Get Started