Help Center > > FAQs> Log Management> How Do I View All SQL Logs Executed by MySQL?

How Do I View All SQL Logs Executed by MySQL?

Updated at: Jul 07, 2021 GMT+08:00

You can use the visualized database management service Data Admin Service (DAS) to quickly search for target SQL execution records. You can also use the SQL audit function of RDS to query all SQL operation records.

Querying SQL Logs Through DAS

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Database > Relational Database Service. The RDS console is displayed.
  4. On the Instance Management page, locate the target DB instance and click Log In in the Operation column.
  5. On the displayed login page, enter the correct username and password and click Log In.
  6. On the top menu bar, choose SQL Operations > SQL History.
  7. On the displayed page, search for execution information about the target SQL statement by time range, database name, or keyword.

    Figure 1 SQL History
    • To access the Database Management page, click a database name.
    • To copy and use your required SQL statements, click the SQL statement in the SQL Statement column.
    • To directly execute a SQL statement, click Open in SQL Window in the Operation column.

Querying SQL Logs Through RDS

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Database > Relational Database Service. The RDS console is displayed.
  4. On the Instance Management page, click the target DB instance.
  5. In the navigation pane on the left, choose SQL Audits.
  6. On the displayed page, select a time range in the upper right corner, select SQL audit logs to be downloaded in the list, and click Download above the list to download SQL audit logs in batches.

    Alternatively, select an audit log and click Download in the Operation column to download an individual SQL audit log.

    Figure 2 Downloading SQL audit logs

  7. The following figure shows the SQL audit log content. For field descriptions, see Table 1.

    Figure 3 MySQL audit logs
    Table 1 Audit log field description

    Parameter

    Description

    record_id

    ID of a single audit log record.

    connection_id

    ID of the session executed by the record, which is the same as the ID in the show processlist command output.

    connection_status

    Session status, which is usually the returned error code of a statement. If a statement is successfully executed, the value 0 is returned.

    name

    Recorded type name. Generally, DML and DDL operations are QUERY, connection and disconnection operations are CONNECT and QUIT, respectively.

    timestamp

    Recorded UTC time.

    command_class

    SQL command type. The value is the parsed SQL type, for example, select or update. (This field does not exist if the connection is disconnected.)

    sqltext

    Executed SQL statement content. (This field does not exist if the audit connection is disconnected.)

    user

    Login account.

    host

    Login host. The value is localhost for local login and is empty for remote login.

    external_user

    External username.

    ip

    IP address of the remotely-connected client. The local IP address is empty.

    default_db

    Default database on which SQL statements are executed.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel