FLUSH PRIVILEGES can reflect the modifications of the grant tables in mysql
database(schema) to your MySQL. *When you directly modify the grant tables, the modifications are not automatically reflected to your MySQL so you need to run FLUSH PRIVILEGES
or restart your MySQL manually and by default, MySQL has mysql
database(schema) which is a system database.
These are the grant tables in mysql
database(schema) as shown below:
user
global_grants
db
tables_priv
columns_priv
procs_priv
proxies_priv
default_roles
role_edges
password_history
So for example, you need to run FLUSH PRIVILEGES
after changing the username root
to john
in user
table of mysql
database(schema) as shown below:
UPDATE mysql.user SET User='john' WHERE User='root';
FLUSH PRIVILEGES;
But, if you forget to run FLUSH PRIVILEGES
after changing the username root
to john
in user
table of mysql
database(schema) as shown below:
UPDATE mysql.user SET User='john' WHERE User='root';
Then, you still cannot log in to MySQL with the username john
as shown below:
mysql -u john -p
So, you still need to log in to MySQL with the username root
as shown below. *Even if you forgot to run FLUSH PRIVILEGES
, you can still run FLUSH PRIVILEGES
to reflect the modification to your MySQL by login with the username root
:
mysql -u root -p
Actually, I recommend to use RENAME USER ...
as shown below to change the username root
to john
because directly modifying the grant tables is sometimes problematic:
RENAME USER 'root'@'localhost' to 'john'@'localhost';
mytable.*
usesmytable
as a database name, not a table name. – Whilom