In the world of hosting, MySQL remains one of the most critical components for powering dynamic websites, e-commerce stores, content management systems (CMS), and SaaS platforms. Whether you’re managing a shared hosting cluster, a VPS infrastructure, or dedicated servers for enterprise clients, having control over MySQL’s internal operations is essential.
One often-overlooked but powerful tool is the FLUSH command — a collection of administrative SQL statements that allow you to reload privileges, clear logs, reset states, and ensure consistency without restarting the server.
The FLUSH statement is used to:
Clear internal caches
Reload configuration files (like privilege tables)
Reset status information
Force MySQL to write buffered data to disk
Only users with the RELOAD privilege (or higher, like SUPER) can execute most FLUSH operations.
Reloads user privileges from the grant tables in the mysql database:
When to use:
After manually editing mysql.user or other grant tables.
When you change user access via direct UPDATE statements instead of GRANT.
Closes all open tables and forces them to be re-opened. Useful in file system maintenance or backups.
You can also flush specific tables:
When to use:
Before performing backups with external tools (e.g., mysqldump –single-transaction).
After large-scale writes that may overload the table cache.
Removes all query results from the query cache (if enabled):
Note: Query cache is deprecated and removed in MySQL 8.0.
Closes and reopens all log files (general log, error log, binary log, relay log).
Or flush a specific type:
When to use:
After log rotation
When logs are moved or archived
To reset logs for debugging or compliance
Resets the host cache of failed client connections.
When to use:
When receiving the error:Host 'xxx' is blocked because of many connection errors
Resets most status variables to zero (does not affect global counters like Uptime).
When to use:
Before benchmarking or performance testing.
To get clean metrics with SHOW STATUS.
Flushes and locks all tables, preventing writes from other sessions.
When to use:
For consistent snapshot backups (e.g., with LVM or file-copying tools).
Important: Always unlock manually with UNLOCK TABLES;
Reloads DES key files used in old DES_ENCRYPT()/DES_DECRYPT() (legacy).
Resets per-user resource limits (like MAX_QUERIES_PER_HOUR) counters.
When to use:
Mid-cycle reset for resource-limited users.
FLUSH QUERY CACHE is removed in MySQL 8.0.
FLUSH DES_KEY_FILE is legacy.
Consider newer alternatives in MySQL 8.0 like RESET PERSIST.
Most FLUSH operations require:
RELOAD privilege
SUPER or SYSTEM_VARIABLES_ADMIN (for sensitive operations in MySQL 8+)
Example:
The FLUSH command family is essential for administrative control in MySQL. Whether you’re managing privileges, logs, or cache states, understanding how and when to use FLUSH helps maintain optimal server performance and reliability without requiring a restart. Use it wisely with proper privileges, especially in production environments.