在创建新表和一个用户时,我通常只调用以下命令:
When creating new tables and a user to go along with it, I usually just invoke the following commands:
CREATE DATABASE mydb;
GRANT ALL PRIVILEGES ON mydb.* TO myuser@localhost IDENTIFIED BY "mypassword";
在发出前两个命令后,我从未需要使用 FLUSH PRIVILEGES
命令.用户可以登录并使用他们的数据库并运行连接到数据库的 PHP 脚本就好了.然而,我几乎在我看过的每个教程中都看到了这个命令.
I have never ever needed to utilize the FLUSH PRIVILEGES
command after issuing the previous two commands. Users can log in and use their database and run PHP scripts which connect to the database just fine. Yet I see this command used in almost every tutorial I look at.
什么时候真正需要 FLUSH PRIVILEGES
命令,什么时候不需要?
When is the FLUSH PRIVILEGES
command really needed and when is it unnecessary?
通过 GRANT 选项分配的权限不需要 FLUSH PRIVILEGES 生效 - MySQL 服务器会注意到这些更改并立即重新加载授权表.
Privileges assigned through GRANT option do not need FLUSH PRIVILEGES to take effect - MySQL server will notice these changes and reload the grant tables immediately.
来自 MySQL 文档:
如果您直接使用以下语句修改授权表INSERT、UPDATE 或 DELETE,您的更改对权限没有影响检查直到您重新启动服务器或告诉它重新加载表.如果您直接更改授权表但忘记重新加载他们,您的更改在您重新启动服务器之前无效.这个可能会让您想知道为什么您的更改似乎没有任何影响!
If you modify the grant tables directly using statements such as INSERT, UPDATE, or DELETE, your changes have no effect on privilege checking until you either restart the server or tell it to reload the tables. If you change the grant tables directly but forget to reload them, your changes have no effect until you restart the server. This may leave you wondering why your changes seem to make no difference!
要告诉服务器重新加载授权表,请执行刷新权限操作.这可以通过发出 FLUSH 来完成PRIVILEGES 语句或通过执行 mysqladmin flush-privileges 或mysqladmin 重载命令.
To tell the server to reload the grant tables, perform a flush-privileges operation. This can be done by issuing a FLUSH PRIVILEGES statement or by executing a mysqladmin flush-privileges or mysqladmin reload command.
如果您使用帐户管理间接修改授权表GRANT、REVOKE、SET PASSWORD 或 RENAME USER 等语句,服务器注意到这些变化并将授权表加载到内存中立即再次.
If you modify the grant tables indirectly using account-management statements such as GRANT, REVOKE, SET PASSWORD, or RENAME USER, the server notices these changes and loads the grant tables into memory again immediately.
这篇关于MySQL:何时真正需要 MySQL 中的 Flush Privileges?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!