# FLUSH

## Syntax

```sql
FLUSH [NO_WRITE_TO_BINLOG | LOCAL]
    flush_option [, flush_option] ...
```

or when flushing tables:

```sql
FLUSH [NO_WRITE_TO_BINLOG | LOCAL] TABLES [table_list]  [table_flush_option]
```

where `table_list` is a list of tables separated by `,` (comma).

## Description

The `FLUSH` statement clears or reloads various internal caches used by MariaDB. To execute `FLUSH`, you must have the `RELOAD` privilege. See [GRANT](https://mariadb.com/docs/server/reference/sql-statements/account-management-sql-statements/grant).

The `RESET` statement is similar to `FLUSH`. See [RESET](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/reset).

You cannot issue a FLUSH statement from within a [stored function](https://mariadb.com/docs/server/server-usage/stored-routines/stored-functions) or a [trigger](https://mariadb.com/docs/server/server-usage/triggers-events/triggers). Doing so within a stored procedure is permitted, as long as it is not called by a stored function or trigger. See [Stored Routine Limitations](https://mariadb.com/docs/server/server-usage/stored-routines/stored-routine-limitations), [Stored Function Limitations](https://mariadb.com/docs/server/server-usage/stored-routines/stored-functions/stored-function-limitations) and [Trigger Limitations](https://mariadb.com/docs/server/server-usage/triggers-events/triggers/trigger-limitations).

If a listed table is a view, an error like the following will be produced:

```
ERROR 1347 (HY000): 'test.v' is not BASE TABLE
```

By default, `FLUSH` statements are written to the [binary log](https://mariadb.com/docs/server/server-management/server-monitoring-logs/binary-log) and will be [replicated](https://mariadb.com/docs/server/ha-and-performance/standard-replication). The `NO_WRITE_TO_BINLOG` keyword (`LOCAL` is an alias) ensures that the statement is not written to the binary log. The different flush options are:

| Option                                              | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| --------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CHANGED\_PAGE\_BITMAPS                              | [XtraDB](https://mariadb.com/docs/server/server-usage/storage-engines/innodb/mariadb-enterprise-server-innodb-operations/innodb-unmaintained/about-xtradb) only. Internal command used for backup purposes. See the [Information Schema CHANGED\_PAGE\_BITMAPS Table](https://mariadb.com/docs/server/reference/system-tables/information-schema/information-schema-tables/information-schema-xtradb-tables/information-schema-changed_page_bitmaps-table).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| CLIENT\_STATISTICS                                  | Reset client statistics (see [SHOW CLIENT\_STATISTICS](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/show/show-client-statistics)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| DES\_KEY\_FILE                                      | Reloads the DES key file (Specified with the [--des-key-file startup option](https://mariadb.com/docs/server/server-management/starting-and-stopping-mariadb/mariadbd-options)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| HOSTS                                               | Flush the hostname cache (used for converting ip to host names and for unblocking blocked hosts. See [max\_connect\_errors](https://mariadb.com/docs/server/server-management/variables-and-modes/server-system-variables#max_connect_errors) and [performance\_schema.host\_cache](https://mariadb.com/docs/server/reference/system-tables/performance-schema/performance-schema-tables/performance-schema-host_cache-table)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| INDEX\_STATISTICS                                   | Reset index statistics (see [SHOW INDEX\_STATISTICS](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/show/show-index-statistics)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ERROR                                               | Closes and reopens the error log file to which the server is writing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| \[ERROR \| ENGINE \| GENERAL \| SLOW \| RELAY] LOGS | Close and reopen the specified log type, or all log types if none are specified. `FLUSH RELAY LOGS [connection-name]` can be used to flush the relay logs for a specific connection. Only one connection can be specified per `FLUSH` command. See [multi-source replication](https://mariadb.com/docs/server/ha-and-performance/standard-replication/multi-source-replication). `FLUSH ENGINE LOGS` deletes all unneeded [Aria](https://mariadb.com/docs/server/server-usage/storage-engines/aria/aria-storage-engine) redo logs. `FLUSH BINARY LOGS DELETE_DOMAIN_ID=(list-of-domains)` can be used to discard obsolete [GTID](https://mariadb.com/docs/server/ha-and-performance/standard-replication/gtid) domains from the server's [binary log](https://mariadb.com/docs/server/server-management/server-monitoring-logs/binary-log) state. In order for this to be successful, no event group from the listed GTID domains can be present in existing binary log files. If some still exist, then they must be purged prior to executing this statement. If the statement completes successfully, it also rotates the binary log. |
| BINARY LOGS                                         | `FLUSH BINARY LOGS` rotates the current [binary log](https://mariadb.com/docs/server/server-management/server-monitoring-logs/binary-log).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| BINARY LOGS DELETE\_DOMAIN\_ID=*list-of-domains*    | `FLUSH BINARY LOGS DELETE_DOMAIN_ID` can be used to discard obsolete [GTID](https://mariadb.com/docs/server/ha-and-performance/standard-replication/gtid) domains from the server's [binary log](https://mariadb.com/docs/server/server-management/server-monitoring-logs/binary-log) state. In order for this to be successful, no event group from the listed GTID domains can be present in existing binary log files. If some still exist, then they must be purged prior to executing this command. If the command completes successfully, then it also rotates the binary log.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| MASTER                                              | Deprecated option, use [RESET MASTER](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/reset) instead.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| PRIVILEGES                                          | Reload all privileges from the privilege tables in the mysql database. If the server is started with --skip-grant-table option, this will activate the privilege tables again.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| QUERY CACHE                                         | Defragment the [query cache](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/buffers-caches-and-threads/query-cache) to better utilize its memory. If you want to reset the query cache, you can do it with [RESET QUERY CACHE](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/reset).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| QUERY\_RESPONSE\_TIME                               | See the [QUERY\_RESPONSE\_TIME](https://mariadb.com/docs/server/reference/plugins/other-plugins/query-response-time-plugin) plugin.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| QUERY\_RESPONSE\_TIME\_READ                         | See the [QUERY\_RESPONSE\_TIME](https://mariadb.com/docs/server/reference/plugins/other-plugins/query-response-time-plugin) plugin. From [MariaDB 11.5](https://app.gitbook.com/s/aEnK0ZXmUbJzqQrTjFyb/community-server/old-releases/11.5/what-is-mariadb-115).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| QUERY\_RESPONSE\_TIME\_READ\_WRITE                  | See the [QUERY\_RESPONSE\_TIME](https://mariadb.com/docs/server/reference/plugins/other-plugins/query-response-time-plugin) plugin. From [MariaDB 11.5](https://app.gitbook.com/s/aEnK0ZXmUbJzqQrTjFyb/community-server/old-releases/11.5/what-is-mariadb-115).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| QUERY\_RESPONSE\_TIME\_WRITE                        | See the [QUERY\_RESPONSE\_TIME](https://mariadb.com/docs/server/reference/plugins/other-plugins/query-response-time-plugin) plugin. From [MariaDB 11.5](https://app.gitbook.com/s/aEnK0ZXmUbJzqQrTjFyb/community-server/old-releases/11.5/what-is-mariadb-115).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| SLAVE                                               | Deprecated option, use [RESET REPLICA or RESET SLAVE](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/replication-statements/reset-replica) instead.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| SSL                                                 | Used to dynamically reinitialize the server's [TLS](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption) context by reloading the files defined by several [TLS system variables](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables). See [FLUSH SSL](#flush-ssl) for more information.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| \[ GLOBAL \| SESSION ] STATUS                       | Resets all [server status variables](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables) that can be reset to 0. Not all global status variables support this, so not all global values are reset. From MariaDB 11.5, `GLOBAL` or `SESSION` can be specified. See [FLUSH STATUS](#flush-status) for more information.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| TABLE\[S]                                           | Close tables given as options or all open tables if no table list was used. Using without any table list will only close tables not in use, and tables not locked by the `FLUSH TABLES` connection. If there are no locked tables, `FLUSH TABLES` will be instant and will not cause any waits, as it no longer waits for tables in use. When a table list is provided, the server will wait for the end of any transactions that are using the tables. Previously, `FLUSH TABLES` only waited for the statements to complete.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| TABLE\[S] ... FOR EXPORT                            | For InnoDB tables, flushes table changes to disk to permit binary table copies while the server is running. See [FLUSH TABLES ... FOR EXPORT](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/flush-commands/flush-tables-for-export) for more.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| TABLE\[S] WITH READ LOCK                            | Closes all open tables. New tables are only allowed to be opened with read locks until an [UNLOCK TABLES](https://mariadb.com/docs/server/reference/sql-statements/transactions/transactions-unlock-tables) is given.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| TABLE\[S] WITH READ LOCK AND DISABLE CHECKPOINT     | As `TABLES WITH READ LOCK`, but also disable all checkpoint writes by transactional table engines. This is useful when doing a disk snapshot of all tables.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| TABLE\_STATISTICS                                   | Reset table statistics (see [SHOW TABLE\_STATISTICS](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/show/show-table-statistics)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| USER\_RESOURCES                                     | Resets all per hour [user resources](https://mariadb.com/docs/server/reference/account-management-sql-statements/grant#setting-per-account-resources-limits). This enables clients that have exhausted their resources to connect again.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| USER\_STATISTICS                                    | Reset user statistics (see [SHOW USER\_STATISTICS](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/show/show-user-statistics)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| USER\_VARIABLES                                     | Reset user variables (see [User-defined variables](https://mariadb.com/docs/server/reference/sql-structure/sql-language-structure/user-defined-variables)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

You can also use the [mariadb-admin](https://mariadb.com/docs/server/clients-and-utilities/administrative-tools/mariadb-admin) client to flush things. Use `mariadb-admin --help` to examine what flush statements it supports.

## FLUSH RELAY LOGS

```sql
FLUSH RELAY LOGS 'connection_name'
```

### Compatibility with MySQL

{% tabs %}
{% tab title="Current" %}
The `FOR CHANNEL` keyword was added for MySQL compatibility. This is identical to using the channel\_name directly after the `FLUSH command`. For example, one can now use:

```sql
FLUSH RELAY LOGS FOR CHANNEL 'connection_name';
```

{% endtab %}

{% tab title="< 10.7.0" %}
`FOR CHANNEL` isn't available.
{% endtab %}
{% endtabs %}

## FLUSH STATUS

[Server status variables](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables) can be reset by executing the following:

```sql
FLUSH STATUS
```

This statement requires the [RELOAD](https://mariadb.com/docs/server/reference/account-management-sql-statements/grant#reload) privilege.

{% tabs %}
{% tab title="Current" %}
Specify FLUSH GLOBAL or FLUSH SESSION. Flushing of global status variables has been moved to `FLUSH GLOBAL STATUS` which is a synonym for `FLUSH STATUS`.\
You can use `old-mode=OLD_FLUSH_STATUS` to restore the old behavior of the `FLUSH STATUS` statement.
{% endtab %}

{% tab title="< 11.5" %}
The variables flushed are mainly session, but some are global. Not all session (or global) variables are flushed - the decision was made per variable.
{% endtab %}
{% endtabs %}

### Global Status Variables that Support `FLUSH STATUS`

Not all global status variables support being reset by `FLUSH STATUS`. The following is an incomplete list of status variables that are reset by `FLUSH GLOBAL STATUS` in MariaDB 11.5 or `FLUSH STATUS` in earlier versions:

* [Aborted\_clients](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#aborted_clients)
* [Aborted\_connects](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#aborted_connects)
* [Binlog\_cache\_disk\_use](https://mariadb.com/docs/server/ha-and-performance/standard-replication/replication-and-binary-log-status-variables#binlog_cache_disk_use)
* [Binlog\_cache\_use](https://mariadb.com/docs/server/ha-and-performance/standard-replication/replication-and-binary-log-status-variables#binlog_cache_use)
* [Binlog\_stmt\_cache\_disk\_use](https://mariadb.com/docs/server/ha-and-performance/standard-replication/replication-and-binary-log-status-variables#binlog_stmt_cache_disk_use)
* [Binlog\_stmt\_cache\_use](https://mariadb.com/docs/server/ha-and-performance/standard-replication/replication-and-binary-log-status-variables#binlog_stmt_cache_use)
* [Connection\_errors\_accept](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#connection_errors_accept)
* [Connection\_errors\_internal](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#connection_errors_internal)
* [Connection\_errors\_max\_connections](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#connection_errors_max_connections)
* [Connection\_errors\_peer\_address](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#connection_errors_peer_address)
* [Connection\_errors\_select](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#connection_errors_select)
* [Connection\_errors\_tcpwrap](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#connection_errors_tcpwrap)
* [Created\_tmp\_files](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#created_tmp_files)
* [Delayed\_errors](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#delayed_errors)
* [Delayed\_writes](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#delayed_writes)
* [Feature\_check\_constraint](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#feature_check_constraint)
* [Feature\_delay\_key\_write](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#feature_delay_key_write)
* [Max\_used\_connection\_time](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#max_used_connection_time)
* [Max\_used\_connections](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#max_used_connections)
* [Opened\_plugin\_libraries](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#opened_plugin_libraries)
* [Performance\_schema\_accounts\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_accounts_lost)
* [Performance\_schema\_cond\_instances\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_cond_instances_lost)
* [Performance\_schema\_digest\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_digest_lost)
* [Performance\_schema\_file\_handles\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_file_handles_lost)
* [Performance\_schema\_file\_instances\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_file_instances_lost)
* [Performance\_schema\_hosts\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_hosts_lost)
* [Performance\_schema\_locker\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_locker_lost)
* [Performance\_schema\_mutex\_instances\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_mutex_instances_lost)
* [Performance\_schema\_rwlock\_instances\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_rwlock_instances_lost)
* [Performance\_schema\_session\_connect\_attrs\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_session_connect_attrs_lost)
* [Performance\_schema\_socket\_instances\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_socket_instances_lost)
* [Performance\_schema\_stage\_classes\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_stage_classes_lost)
* [Performance\_schema\_statement\_classes\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_statement_classes_lost)
* [Performance\_schema\_table\_handles\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_table_handles_lost)
* [Performance\_schema\_table\_instances\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_table_instances_lost)
* [Performance\_schema\_thread\_instances\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_thread_instances_lost)
* [Performance\_schema\_users\_lost](https://mariadb.com/docs/server/system-tables/performance-schema/performance-schema-status-variables#performance_schema_users_lost)
* [Qcache\_hits](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#qcache_hits)
* [Qcache\_inserts](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#qcache_inserts)
* [Qcache\_lowmem\_prunes](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#qcache_lowmem_prunes)
* [Qcache\_not\_cached](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#qcache_not_cached)
* [Rpl\_semi\_sync\_master\_no\_times](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/semisynchronous-replication-plugin-status-variables#rpl_semi_sync_master_no_times)
* [Rpl\_semi\_sync\_master\_no\_tx](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/semisynchronous-replication-plugin-status-variables#rpl_semi_sync_master_no_tx)
* [Rpl\_semi\_sync\_master\_timefunc\_failures](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/semisynchronous-replication-plugin-status-variables#rpl_semi_sync_master_timefunc_failures)
* [Rpl\_semi\_sync\_master\_wait\_pos\_backtraverse](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/semisynchronous-replication-plugin-status-variables#rpl_semi_sync_master_wait_pos_backtraverse)
* [Rpl\_semi\_sync\_master\_yes\_tx](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/semisynchronous-replication-plugin-status-variables#rpl_semi_sync_master_yes_tx)
* [Rpl\_transactions\_multi\_engine](https://mariadb.com/docs/server/ha-and-performance/standard-replication/replication-and-binary-log-status-variables#rpl_transactions_multi_engine)
* [Server\_audit\_writes\_failed](https://mariadb.com/docs/server/plugins/mariadb-audit-plugin/mariadb-audit-plugin-status-variables#server_audit_writes_failed)
* [Slave\_retried\_transactions](https://mariadb.com/docs/server/ha-and-performance/standard-replication/replication-and-binary-log-status-variables#slave_retried_transactions)
* [Slow\_launch\_threads](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#slow_launch_threads)
* [Ssl\_accept\_renegotiates](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_accept_renegotiates)
* [Ssl\_accepts](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_accepts)
* [Ssl\_callback\_cache\_hits](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_callback_cache_hits)
* [Ssl\_client\_connects](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_client_connects)
* [Ssl\_connect\_renegotiates](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_connect_renegotiates)
* [Ssl\_ctx\_verify\_depth](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_ctx_verify_depth)
* [Ssl\_ctx\_verify\_mode](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_ctx_verify_mode)
* [Ssl\_finished\_accepts](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_finished_accepts)
* [Ssl\_finished\_connects](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_finished_connects)
* [Ssl\_session\_cache\_hits](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_session_cache_hits)
* [Ssl\_session\_cache\_misses](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_session_cache_misses)
* [Ssl\_session\_cache\_overflows](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_session_cache_overflows)
* [Ssl\_session\_cache\_size](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_session_cache_size)
* [Ssl\_session\_cache\_timeouts](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_session_cache_timeouts)
* [Ssl\_sessions\_reused](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_sessions_reused)
* [Ssl\_used\_session\_cache\_entries](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/system-variables/ssltls-status-variables#ssl_used_session_cache_entries)
* [Subquery\_cache\_hit](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#subquery_cache_hit)
* [Subquery\_cache\_miss](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#subquery_cache_miss)
* [Table\_locks\_immediate](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#table_locks_immediate)
* [Table\_locks\_waited](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#table_locks_waited)
* [Tc\_log\_max\_pages\_used](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#tc_log_max_pages_used)
* [Tc\_log\_page\_waits](https://mariadb.com/docs/server/server-management/variables-and-modes/server-status-variables#tc_log_page_waits)
* [Transactions\_gtid\_foreign\_engine](https://mariadb.com/docs/server/ha-and-performance/standard-replication/replication-and-binary-log-status-variables#transactions_gtid_foreign_engine)
* [Transactions\_multi\_engine](https://mariadb.com/docs/server/ha-and-performance/standard-replication/replication-and-binary-log-status-variables#transactions_multi_engine)

## FLUSH TABLES

{% tabs %}
{% tab title="Current" %}
`FLUSH TABLES` doesn't cause [InnoDB statistics](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/query-optimizations/statistics-for-optimizing-queries/innodb-persistent-statistics) to be reloaded or recalculated. [RENAME TABLE](https://mariadb.com/docs/server/reference/sql-statements/data-definition/rename-table), however, triggers a reload of the statistics.
{% endtab %}

{% tab title="< 11.8.2 / 11.4.6" %}
`FLUSH TABLES` causes [InnoDB statistics](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/query-optimizations/statistics-for-optimizing-queries/innodb-persistent-statistics) to be reloaded or recalculated.
{% endtab %}

{% tab title="< 10.11.12" %}
`FLUSH TABLES` causes [InnoDB statistics](https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/query-optimizations/statistics-for-optimizing-queries/innodb-persistent-statistics) to be reloaded or recalculated.
{% endtab %}
{% endtabs %}

The purpose of `FLUSH TABLES` is to clean up the open table cache and table definition cache of tables that are not in use. This frees up memory and file descriptors. Normally this is not needed as the caches works on a first-in, first-out basis, but can be useful if the server seems to use too much memory for some reason.

In the following, the purpose of specific `FLUSH TABLES` statements is detailed.

### FLUSH TABLES WITH READ LOCK

`FLUSH TABLES WITH READ LOCK` is useful if you want to take a backup of some tables. When the statement returns, all write access to tables is blocked and all tables are marked as "properly closed" on disk. The tables can still be used for read operations.

### FLUSH TABLES *table\_list*

` FLUSH TABLES`` `` `*`table_list`* is useful if you want to copy a table object or files to or from the server. This statement puts a lock that stops new users of the table and will wait until everyone has stopped using the table. The table is then removed from the table definition and table cache.

Note that it's up to the user to ensure that no one is accessing the table between issuing the `FLUSH TABLES` statement and the time the table is copied to or from the server. This can be secured by using [LOCK TABLES](https://mariadb.com/docs/server/reference/sql-statements/transactions/lock-tables).

If there are any tables locked by the connection that is using `FLUSH TABLES` all the locked tables will be closed as part of the flush and reopened and relocked before `FLUSH TABLES` returns. This allows one to copy the table after `FLUSH TABLES` returns without having any writes on the table. For now this works with most tables, except InnoDB as InnoDB may do background purges on the table even while it's write locked.

### FLUSH TABLES *table\_list* WITH READ LOCK

` FLUSH TABLES`` `` `*`table_list`*` `` ``WITH READ LOCK ` works as `FLUSH TABLES WITH READ LOCK`, but only the tables listed are properly closed. In practice, this works exactly like `FLUSH TABLES WITH READ LOCK`, because the `FLUSH` statement must wait for all write operations to end – this is because MariaDB depends on a global read lock for this statement.

### Implementation of FLUSH TABLES

* Free memory and file descriptors not in use

### Implementation of FLUSH TABLES WITH READ LOCK

* Lock all tables read only for simple old style backup.
* All background writes are suspended and tables are marked as closed.
* No statement requiring table changes are allowed for any user until `UNLOCK TABLES`.

Instead of using `FLUSH TABLE WITH READ LOCK` one should in most cases instead use [BACKUP STAGE BLOCK\_COMMIT](https://mariadb.com/docs/server/reference/sql-statements/administrative-sql-statements/backup-commands/backup-stage).

### Implementation of FLUSH TABLES *table\_list*

* Free memory and file descriptors for tables not in use from table list.
* Lock given tables as read only.
* Wait until all translations has ended that uses any of the given tables.
* Wait until all background writes are suspended and tables are marked as closed.

### Implementation of FLUSH TABLES *table\_list* FOR EXPORT

* Free memory and file descriptors for tables not in use from table list.
* Lock given tables as read.
* Wait until all background writes are suspended and tables are marked as closed.
* Check that all tables supports `FOR EXPORT`.
* No changes to these tables allowed until `UNLOCK TABLES`.

This is basically the same behavior as in older MariaDB versions if you first lock the tables, then do `FLUSH TABLES`. The tables will be copyable until you issue `UNLOCK TABLES`.

## FLUSH SSL

The `FLUSH SSL` command can be used to dynamically reinitialize the server's [TLS](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption) context. This is most useful if you need to replace a certificate that is about to expire without restarting the server.

This operation is performed by reloading the files defined by the following [TLS system variables](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables):

* [ssl\_cert](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables#ssl_cert)
* [ssl\_key](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables#ssl_key)
* [ssl\_ca](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables#ssl_ca)
* [ssl\_capath](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables#ssl_capath)
* [ssl\_crl](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables#ssl_crl)
* [ssl\_crlpath](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables#ssl_crlpath)

These [TLS system variables](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables) are not dynamic, so their values can **not** be changed without restarting the server.

If you want to dynamically reinitialize the server's [TLS](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption) context, then you need to change the certificate and key files at the relevant paths defined by these [TLS system variables](https://mariadb.com/docs/server/security/encryption/data-in-transit-encryption/ssltls-system-variables), without actually changing the values of the variables. See [MDEV-19341](https://jira.mariadb.org/browse/MDEV-19341) for more information.

## Reducing Memory Usage

To flush some of the global caches that take up memory, you could execute the following command:

```sql
FLUSH LOCAL HOSTS,
   QUERY CACHE, 
   TABLE_STATISTICS, 
   INDEX_STATISTICS, 
   USER_STATISTICS;
```

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}
