Skip to content
logo
Percona Server for MySQL
User statistics
Initializing search
    percona/psmysql-docs
    percona/psmysql-docs
    • Home
      • The Percona XtraDB storage engine
      • List of features available in Percona Server for MySQL releases
      • Percona Server for MySQL feature comparison
      • Changed in Percona Server 8.0
      • Understand version numbers
      • Install Percona Server for MySQL
        • Install using APT repository
        • Files in DEB package
        • Build APT packages
        • Install from downloaded DEB packages
        • Apt pinning
        • Run Percona Server for MySQL
        • Uninstall
        • Install using a RPM repository
        • Files in RPM package
        • Install from downloaded RPM packages
        • Run Percona Server for MySQL
        • Uninstall
        • Install with binary tarballs
        • Binary tarballs available
        • Install Percona Server for MySQL from a source tarball
        • Compile Percona Server for MySQL 8.0 from source
      • Post-installation
      • Percona Server for MySQL in-place upgrading guide: from 5.7 to 8.0
      • Upgrade using the Percona repositories
      • Upgrade from systems that use the MyRocks or TokuDB storage engine and partitioned tables
      • Upgrade using Standalone Packages
      • Downgrade Percona Server for MySQL
      • Running Percona Server for MySQL in a Docker Container
      • Docker environment variables
      • Improved InnoDB I/O scalability
      • Adaptive network buffers
      • Multiple page asynchronous I/O requests
      • Thread pool
      • XtraDB performance improvements for I/O-bound highly-concurrent workloads
      • Prefix index queries optimization
      • Limit the estimation of records in a Query
      • Jemalloc memory allocation profiling
      • The ProcFS plugin
      • Binary logs and replication improvements
      • Compressed columns with dictionaries
      • Extended SELECT INTO OUTFILE/DUMPFILE
      • Extended SET VAR optimizer hint
      • Improved MEMORY storage engine
      • Suppress warning messages
      • Limiting the disk space used by binary log files
      • Support for PROXY protocol
      • SEQUENCE_TABLE(n) function
      • Slow query log rotation and expiration
      • Trigger updates
      • Extended mysqlbinlog
      • Extended mysqldump
      • InnoDB full-text search improvements
      • Too many connections warning
      • Handle corrupted tables
      • Percona Toolkit UDFs
      • Kill idle transactions
      • XtraDB changed page tracking
      • Enforcing storage engine
      • Expanded fast index creation
      • Backup locks
      • Audit log plugin
      • Start transaction with consistent snapshot
      • Extended SHOW GRANTS
      • Utility user
      • Working with SELinux
      • Working with AppArmor
      • PAM authentication plugin
      • Server variables
      • SSL improvements
      • Data masking
        • Using LDAP authentication plugins
        • LDAP authentication plugin system variables
        • Data at Rest Encryption
        • Use the keyring component or keyring plugin
          • Using the Key Management Interoperability Protocol (KMIP)
          • Use the Amazon Key Management Service (AWS KMS)
          • FIDO authentication plugin
        • Encryption functions
        • Encrypt File-Per-Table Tablespace
        • Encrypt schema or general tablespace
        • Encrypt system tablespace
        • Encrypt temporary files
        • Encrypt Binary Log Files and Relay Log Files
        • Encrypting the Redo Log data
        • Encrypt the undo tablespace
        • Rotate the master key
        • Advanced encryption key rotation
        • Encrypt doublewrite buffers
        • Verify the encryption for tables, tablespaces, and schemas
      • User statistics
        • Version specific information
        • Other information
        • System variables
          • userstat
          • thread_statistics
        • INFORMATION_SCHEMA Tables
          • INFORMATION_SCHEMA.CLIENT_STATISTICS
        • INFORMATION_SCHEMA tables
          • INFORMATION_SCHEMA.INDEX_STATISTICS
          • INFORMATION_SCHEMA.TABLE_STATISTICS
          • INFORMATION_SCHEMA.THREAD_STATISTICS
          • INFORMATION_SCHEMA.USER_STATISTICS
        • Commands Provided
        • Status Variables
          • Com_show_client_statistics
          • Com_show_index_statistics
          • Com_show_table_statistics
          • Com_show_thread_statistics
          • Com_show_user_statistics
      • Slow query log
      • Extended show engine InnoDB status
      • Show storage engines
      • Process list
      • Misc. INFORMATION_SCHEMA tables
      • Thread based profiling
      • InnoDB page fragmentation counters
      • Stacktrace
      • Libcoredumper
      • Manage group replication flow control
      • Group replication system variables
      • Percona MyRocks introduction
      • Percona MyRocks installation guide
      • Updated supported features
      • MyRocks limitations
      • Differences between Percona MyRocks and Facebook MyRocks
      • MyRocks Information Schema tables
      • MyRocks server variables
      • MyRocks status variables
      • Gap locks detection
      • Data loading
      • Installing and configuring Percona Server for MySQL with ZenFS support
      • TokuDB introduction
      • TokuDB installation
      • Use TokuDB
      • Fast updates with TokuDB
      • TokuDB files and file types
      • TokuDB file management
      • TokuDB background ANALYZE TABLE
      • TokuDB variables
      • TokuDB status variables
      • TokuDB fractal tree indexing
      • TokuDB troubleshooting
      • TokuDB Performance Schema integration
      • Frequently asked questions
      • Migrate and removing the TokuDB storage engine
      • Percona TokuBackup
      • Release notes index
      • Percona Server for MySQL 8.0.32-24 (2023-03-20)
      • Percona Server for MySQL 8.0.31-23 (2023-02-09)
      • Percona Server for MySQL 8.0.30-22 Update (2022-11-21)
      • Percona Server for MySQL 8.0.30-22 (2022-11-21)
      • Percona Server for MySQL 8.0.29-21 (2022-08-08)
      • Percona Server for MySQL 8.0.28-20 (2022-06-20)
      • Percona Server for MySQL 8.0.28-19 (2022-05-12)
      • Percona Server for MySQL 8.0.27-18 (2022-03-02)
      • Percona Server for MySQL 8.0.26-17 (2022-01-26)
      • Percona Server for MySQL 8.0.26-16 (2021-10-20)
      • Percona Server for MySQL 8.0.25-15 (2021-07-13)
      • Percona Server for MySQL 8.0.23-14 (2021-05-12)
      • Percona Server for MySQL 8.0.22-13 (2020-12-14)
      • Percona Server for MySQL 8.0.21-12 (2020-10-13)
      • Percona Server for MySQL 8.0.20-11 (2020-07-21)
      • Percona Server for MySQL 8.0.19-10 (2020-03-23)
      • Percona Server for MySQL 8.0.18-9
      • Percona Server for MySQL 8.0.17-8
      • Percona Server for MySQL 8.0.16-7
      • Percona Server for MySQL 8.0.15-6
      • Percona Server for MySQL 8.0.15-5
      • Percona Server for MySQL 8.0.14
      • Percona Server for MySQL 8.0.13-4
      • Percona Server for MySQL 8.0.13-3
      • Percona Server for MySQL 8.0.12-2rc1
      • List of variables introduced in Percona Server for MySQL 8.0
      • Development of Percona Server for MySQL
      • Trademark policy
      • Index of INFORMATION_SCHEMA tables
      • Frequently asked questions
      • Copyright and licensing information
      • Glossary

    • Version specific information
    • Other information
    • System variables
      • userstat
      • thread_statistics
    • INFORMATION_SCHEMA Tables
      • INFORMATION_SCHEMA.CLIENT_STATISTICS
    • INFORMATION_SCHEMA tables
      • INFORMATION_SCHEMA.INDEX_STATISTICS
      • INFORMATION_SCHEMA.TABLE_STATISTICS
      • INFORMATION_SCHEMA.THREAD_STATISTICS
      • INFORMATION_SCHEMA.USER_STATISTICS
    • Commands Provided
    • Status Variables
      • Com_show_client_statistics
      • Com_show_index_statistics
      • Com_show_table_statistics
      • Com_show_thread_statistics
      • Com_show_user_statistics

    User statistics¶

    This feature adds several INFORMATION_SCHEMA tables, several commands, and the userstat variable. The tables and commands can be used to understand the server activity better and identify the source of the load.

    The functionality is disabled by default and must be enabled by setting userstat to ON. It works by keeping several hash tables in memory. To avoid contention over global mutexes, each connection has its own local statistics, which are occasionally merged into the global statistics, and the local statistics are then reset to 0.

    Version specific information¶

    • 8.0.12-1: The feature was ported from Percona Server for MySQL 5.7.

    Other information¶

    • Author/Origin: Google; Percona added the INFORMATION_SCHEMA tables and the userstat variable.

    System variables¶

    userstat¶

    Option Description
    Command-line Yes
    Config file Yes
    Scope Global
    Dynamic Yes
    Data type BOOLEAN
    Default OFF
    Range ON/OFF

    Enables or disables collection of statistics. The default is OFF, meaning no statistics are gathered. This is to ensure that the statistics collection doesn’t cause any extra load on the server unless desired.

    thread_statistics¶

    Option Description
    Command-line Yes
    Config file Yes
    Scope Global
    Dynamic Yes
    Data type BOOLEAN
    Default OFF
    Range ON/OFF

    Enables or disables collection of thread statistics. The default is OFF, meaning no thread statistics are gathered. This is to ensure that the statistics collection doesn’t cause any extra load on the server unless desired. The variable userstat must be enabled as well in order for thread statistics to be collected.

    INFORMATION_SCHEMA Tables¶

    INFORMATION_SCHEMA.CLIENT_STATISTICS¶

    Column Name Description
    ‘CLIENT’ ‘The IP address or hostname from which the connection originated.’
    ‘TOTAL_CONNECTIONS’ ‘The number of connections created for this client.’
    ‘CONCURRENT_CONNECTIONS’ ‘The number of concurrent connections for this client.’
    ‘CONNECTED_TIME’ ‘The cumulative number of seconds elapsed while there were connections from this client.’
    ‘BUSY_TIME’ ‘The cumulative number of seconds there was activity on connections from this client.’
    ‘CPU_TIME’ ‘The cumulative CPU time elapsed, in seconds, while servicing this client’s connections.’
    ‘BYTES_RECEIVED’ ‘The number of bytes received from this client’s connections.’
    ‘BYTES_SENT’ ‘The number of bytes sent to this client’s connections.’
    ‘BINLOG_BYTES_WRITTEN’ ‘The number of bytes written to the binary log from this client’s connections.’
    ‘ROWS_FETCHED’ ‘The number of rows fetched by this client’s connections.’
    ‘ROWS_UPDATED’ ‘The number of rows updated by this client’s connections.’
    ‘TABLE_ROWS_READ’ ‘The number of rows read from tables by this client’s connections. (It may be different from ROWS_FETCHED.)’
    ‘SELECT_COMMANDS’ ‘The number of SELECT commands executed from this client’s connections.’
    ‘UPDATE_COMMANDS’ ‘The number of UPDATE commands executed from this client’s connections.’
    ‘OTHER_COMMANDS’ ‘The number of other commands executed from this client’s connections.’
    ‘COMMIT_TRANSACTIONS’ ‘The number of COMMIT commands issued by this client’s connections.’
    ‘ROLLBACK_TRANSACTIONS’ ‘The number of ROLLBACK commands issued by this client’s connections.’
    ‘DENIED_CONNECTIONS’ ‘The number of connections denied to this client.’
    ‘LOST_CONNECTIONS’ ‘The number of this client’s connections that were terminated uncleanly.’
    ‘ACCESS_DENIED’ ‘The number of times this client’s connections issued commands that were denied.’
    ‘EMPTY_QUERIES’ ‘The number of times this client’s connections sent empty queries to the server.’

    This table holds statistics about client connections. The Percona version of the feature restricts this table’s visibility to users who have the SUPER or PROCESS privilege.

    For example:

    mysql>SELECT * FROM INFORMATION_SCHEMA.CLIENT_STATISTICS\G
    
    Expected output
    *************************** 1. row ***************************
                    CLIENT: 10.1.12.30
         TOTAL_CONNECTIONS: 20
    CONCURRENT_CONNECTIONS: 0
            CONNECTED_TIME: 0
                 BUSY_TIME: 93
                  CPU_TIME: 48
            BYTES_RECEIVED: 5031
                BYTES_SENT: 276926
       BINLOG_BYTES_WRITTEN: 217
              ROWS_FETCHED: 81
              ROWS_UPDATED: 0
           TABLE_ROWS_READ: 52836023
           SELECT_COMMANDS: 26
           UPDATE_COMMANDS: 1
            OTHER_COMMANDS: 145
       COMMIT_TRANSACTIONS: 1
     ROLLBACK_TRANSACTIONS: 0
        DENIED_CONNECTIONS: 0
          LOST_CONNECTIONS: 0
             ACCESS_DENIED: 0
             EMPTY_QUERIES: 0
    

    INFORMATION_SCHEMA tables¶

    INFORMATION_SCHEMA.INDEX_STATISTICS¶

    Column Name Description
    ‘TABLE_SCHEMA’ ‘The schema (database) name.’
    ‘TABLE_NAME’ ‘The table name.’
    ‘INDEX_NAME’ ‘The index name (as visible in SHOW CREATE TABLE).’
    ‘ROWS_READ’ ‘The number of rows read from this index.’

    This table shows statistics on index usage. An older version of the feature contained a single column that had the TABLE_SCHEMA, TABLE_NAME, and INDEX_NAME columns concatenated together. The Percona version of the feature separates these into three columns. Users can see entries only for tables to which they have SELECT access.

    This table makes it possible to do many things that were difficult or impossible previously. For example, you can use it to find unused indexes and generate DROP commands to remove them.

    Example:

    mysql> SELECT * FROM INFORMATION_SCHEMA.INDEX_STATISTICS WHERE TABLE_NAME='tables_priv';
    
    Expected output
    +--------------+-----------------------+--------------------+-----------+
    | TABLE_SCHEMA | TABLE_NAME            | INDEX_NAME         | ROWS_READ |
    +--------------+-----------------------+--------------------+-----------+
    | mysql        | tables_priv           | PRIMARY            |         2 |
    +--------------+-----------------------+--------------------+-----------+
    

    Note

    The current implementation of index statistics doesn’t support partitioned tables.

    INFORMATION_SCHEMA.TABLE_STATISTICS¶

    Column Name Description
    ‘TABLE_SCHEMA’ ‘The schema (database) name.’
    ‘TABLE_NAME’ ‘The table name.’
    ‘ROWS_READ’ ‘The number of rows read from the table.’
    ‘ROWS_CHANGED’ ‘The number of rows changed in the table.’
    ‘ROWS_CHANGED_X_INDEXES’ ‘The number of rows changed in the table, multiplied by the number of indexes changed.’

    This table is similar in function to the INDEX_STATISTICS table.

    For example:

    mysql> SELECT * FROM INFORMATION_SCHEMA.TABLE_STATISTICS WHERE TABLE_NAME=``tables_priv``;
    
    Expected output
    +--------------+-------------------------------+-----------+--------------+------------------------+
    | TABLE_SCHEMA | TABLE_NAME                    | ROWS_READ | ROWS_CHANGED | ROWS_CHANGED_X_INDEXES |
    +--------------+-------------------------------+-----------+--------------+------------------------+
    | mysql        | tables_priv                   |         2 |            0 |                      0 |
    +--------------+-------------------------------+-----------+--------------+------------------------+
    

    Note

    The current implementation of table statistics doesn’t support partitioned tables.

    INFORMATION_SCHEMA.THREAD_STATISTICS¶

    Column Name Description
    ‘THREAD_ID’ ‘Thread ID’
    ‘TOTAL_CONNECTIONS’ ‘The number of connections created from this thread.’
    ‘CONNECTED_TIME’ ‘The cumulative number of seconds elapsed while there were connections from this thread.’
    ‘BUSY_TIME’ ‘The cumulative number of seconds there was activity from this thread.’
    ‘CPU_TIME’ ‘The cumulative CPU time elapsed while servicing this thread.’
    ‘BYTES_RECEIVED’ ‘The number of bytes received from this thread.’
    ‘BYTES_SENT’ ‘The number of bytes sent to this thread.’
    ‘BINLOG_BYTES_WRITTEN’ ‘The number of bytes written to the binary log from this thread.’
    ‘ROWS_FETCHED’ ‘The number of rows fetched by this thread.’
    ‘ROWS_UPDATED’ ‘The number of rows updated by this thread.’
    ‘TABLE_ROWS_READ’ ‘The number of rows read from tables by this tread.’
    ‘SELECT_COMMANDS’ ‘The number of SELECT commands executed from this thread.’
    ‘UPDATE_COMMANDS’ ‘The number of UPDATE commands executed from this thread.’
    ‘OTHER_COMMANDS’ ‘The number of other commands executed from this thread.’
    ‘COMMIT_TRANSACTIONS’ ‘The number of COMMIT commands issued by this thread.’
    ‘ROLLBACK_TRANSACTIONS’ ‘The number of ROLLBACK commands issued by this thread.’
    ‘DENIED_CONNECTIONS’ ‘The number of connections denied to this thread.’
    ‘LOST_CONNECTIONS’ ‘The number of thread connections that were terminated uncleanly.’
    ‘ACCESS_DENIED’ ‘The number of times this thread issued commands that were denied.’
    ‘EMPTY_QUERIES’ ‘The number of times this thread sent empty queries to the server.’
    ‘TOTAL_SSL_CONNECTIONS’ ‘The number of thread connections that used SSL.’

    In order for this table to be populated with statistics, the additional variable thread_statistics should be set to ON.

    INFORMATION_SCHEMA.USER_STATISTICS¶

    Column Name Description
    ‘USER’ ‘The username. The value #mysql_system_user# appears when there is no username (such as for the replica SQL thread).’
    ‘TOTAL_CONNECTIONS’ ‘The number of connections created from this user.’
    ‘CONCURRENT_CONNECTIONS’ ‘The number of concurrent connections for this user.’
    ‘CONNECTED_TIME’ ‘The cumulative number of seconds elapsed while there were connections from this user.’
    ‘BUSY_TIME’ ‘The cumulative number of seconds there was activity on connections from this user.’
    ‘CPU_TIME’ ‘The cumulative CPU time elapsed, in seconds, while servicing this user’s connections.’
    ‘BYTES_RECEIVED’ ‘The number of bytes received from this user’s connections.’
    ‘BYTES_SENT’ ‘The number of bytes sent to this user’s connections.’
    ‘BINLOG_BYTES_WRITTEN’ ‘The number of bytes written to the binary log from this user’s connections.’
    ‘ROWS_FETCHED’ ‘The number of rows fetched by this user’s connections.’
    ‘ROWS_UPDATED’ ‘The number of rows updated by this user’s connections.’
    ‘TABLE_ROWS_READ’ ‘The number of rows read from tables by this user’s connections. (It may be different from ROWS_FETCHED.)’
    ‘SELECT_COMMANDS’ ‘The number of SELECT commands executed from this user’s connections.’
    ‘UPDATE_COMMANDS’ ‘The number of UPDATE commands executed from this user’s connections.’
    ‘OTHER_COMMANDS’ ‘The number of other commands executed from this user’s connections.’
    ‘COMMIT_TRANSACTIONS’ ‘The number of COMMIT commands issued by this user’s connections.’
    ‘ROLLBACK_TRANSACTIONS’ ‘The number of ROLLBACK commands issued by this user’s connections.’
    ‘DENIED_CONNECTIONS’ ‘The number of connections denied to this user.’
    ‘LOST_CONNECTIONS’ ‘The number of this user’s connections that were terminated uncleanly.’
    ‘ACCESS_DENIED’ ‘The number of times this user’s connections issued commands that were denied.’
    ‘EMPTY_QUERIES’ ‘The number of times this user’s connections sent empty queries to the server.’

    This table contains information about user activity. The Percona version of the patch restricts this table’s visibility to users who have the SUPER or PROCESS privilege.

    The table gives answers to questions such as which users cause the most load, and whether any users are being abusive. It also lets you measure how close to capacity the server may be. For example, you can use it to find out whether replication is likely to start falling behind.

    Example:

    mysql>SELECT * FROM INFORMATION_SCHEMA.USER_STATISTICS\G
    
    Expected output
    *************************** 1. row ***************************
                      USER: root
         TOTAL_CONNECTIONS: 5592
     CONCURRENT_CONNECTIONS: 0
             CONNECTED_TIME: 6844
                 BUSY_TIME: 179
                  CPU_TIME: 72
            BYTES_RECEIVED: 603344
                BYTES_SENT: 15663832
      BINLOG_BYTES_WRITTEN: 217
              ROWS_FETCHED: 9793
              ROWS_UPDATED: 0
           TABLE_ROWS_READ: 52836023
           SELECT_COMMANDS: 9701
           UPDATE_COMMANDS: 1
            OTHER_COMMANDS: 2614
       COMMIT_TRANSACTIONS: 1
     ROLLBACK_TRANSACTIONS: 0
        DENIED_CONNECTIONS: 0
          LOST_CONNECTIONS: 0
             ACCESS_DENIED: 0
             EMPTY_QUERIES: 0
    

    Commands Provided¶

    • FLUSH CLIENT_STATISTICS

    • FLUSH INDEX_STATISTICS

    • FLUSH TABLE_STATISTICS

    • FLUSH THREAD_STATISTICS

    • FLUSH USER_STATISTICS

    These commands discard the specified type of stored statistical information.

    • SHOW CLIENT_STATISTICS

    • SHOW INDEX_STATISTICS

    • SHOW TABLE_STATISTICS

    • SHOW THREAD_STATISTICS

    • SHOW USER_STATISTICS

    These commands are another way to display the information you can get from the INFORMATION_SCHEMA tables. The commands accept WHERE clauses. They also accept but ignore LIKE clauses.

    Status Variables¶

    Com_show_client_statistics¶

    Option Description
    Scope Global/Session
    Data type numeric

    The Com_show_client_statistics statement counter variable indicates the number of times the statement SHOW CLIENT_STATISTICS has been executed.

    Com_show_index_statistics¶

    Option Description
    Scope Global/Session
    Data type numeric

    The Com_show_index_statistics statement counter variable indicates the number of times the statement SHOW INDEX_STATISTICS has been executed.

    Com_show_table_statistics¶

    Option Description
    Scope Global/Session
    Data type numeric

    The Com_show_table_statistics statement counter variable indicates the number of times the statement SHOW TABLE_STATISTICS has been executed.

    Com_show_thread_statistics¶

    Option Description
    Scope Global/Session
    Data type numeric

    The Com_show_thread_statistics statement counter variable indicates the number of times the statement SHOW THREAD_STATISTICS has been executed.

    Com_show_user_statistics¶

    Option Description
    Scope Global/Session
    Data type numeric

    The Com_show_user_statistics statement counter variable indicates the number of times the statement SHOW USER_STATISTICS has been executed.

    Contact us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: 2023-01-12
    Percona LLC and/or its affiliates, © 2023
    Made with Material for MkDocs

    Cookie consent

    We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.