FLUSH PRIVILEGES - MySQL


Overview

The FLUSH PRIVILEGES command in MySQL is used to force the server to reload the grant tables into memory. This is necessary whenever you make changes to user privileges so that the server is aware of the updated permissions.

Syntax

FLUSH PRIVILEGES

Options/Flags

There are no options or flags available for this command.

Examples

Simple Example:

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Complex Example:

mysql> GRANT SELECT ON mydb.* TO 'newuser'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

In this example, a new user is granted permissions, and then the privileges are flushed to ensure the server is aware of the changes.

Common Issues

  • Permission denied error after revoking privileges:

    • Ensure that the user revoking the privileges has sufficient permissions (e.g., SUPER or GRANT OPTION) to do so.
  • Server is not responding after FLUSH PRIVILEGES:

    • Check the server logs for any errors or warnings.
    • Try restarting the server to resolve any temporary issues.

Integration

FLUSH PRIVILEGES is often used in conjunction with commands that modify user permissions, such as GRANT, REVOKE, and CREATE USER. It should be executed after making any changes to user privileges to ensure that the server is aware of the changes.

  • GRANT: Grants permissions to users.
  • REVOKE: Revokes permissions from users.