如果 mysqld 服务器在启动时没有使用 --skip-grant-tables 选项,它将在启动过程中将所有权限表内容读取到内存中。此时,内存中的表对于访问控制开始生效。If the mysqld server is started without the
--skip-grant-tables option, it
reads all grant table contents into memory during its startup
sequence. The in-memory tables become effective for access control
at that point.
如果您使用账户管理语句间接修改授权表,服务器会注意到这些更改,并立即将授权表重新加载到内存中。账户管理语句在第 15.7.1 节,“账户管理语句”中有描述。示例包括GRANT、REVOKE、SET
PASSWORD 和 RENAME
USER。If you modify the grant tables indirectly using an
account-management statement, the server notices these changes and
loads the grant tables into memory again immediately.
Account-management statements are described in
Section 15.7.1, “Account Management Statements”. Examples include
GRANT,
REVOKE, SET
PASSWORD, and RENAME
USER.
如果你使用诸如 INSERT、UPDATE 或 DELETE(不推荐)之类的语句直接修改授权表,修改不会对权限检查产生效果,直到你告诉服务器重新加载这些表或重启服务器。因此,如果你直接更改授权表但忘记重新加载它们,这些更改在你重启服务器之前将 没有效果。这可能会让你纳闷,为什么你的更改似乎没有任何作用!If you modify the grant tables directly using statements such as
INSERT,
UPDATE, or
DELETE (which is not recommended),
the changes have no effect on privilege checking until you either
tell the server to reload the tables or restart it. Thus, if you
change the grant tables directly but forget to reload them, the
changes have no effect until you restart the
server. This may leave you wondering why your changes seem to make
no difference!
要告诉服务器重新加载权限表,请执行 flush-privileges 操作。这可以通过执行 FLUSH PRIVILEGES 语句,或通过执行 mysqladmin flush-privileges 或 mysqladmin reload 命令来完成。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.
权限表重新加载会影响每个现有客户端会话的权限,具体如下:A grant table reload affects privileges for each existing client session as follows:
表和列权限的更改将在客户端的下一次请求时生效。Table and column privilege changes take effect with the client's next request.
数据库权限更改将在客户端下次执行
USE db_name语句时生效。Database privilege changes take effect the next time the client executes aUSEstatement.db_nameNote客户端应用程序可能会缓存数据库名称;因此,如果不实际切换到不同的数据库,这种效果可能对它们不可见。Client applications may cache the database name; thus, this effect may not be visible to them without actually changing to a different database.
对于已连接的客户端,静态全局特权和密码不受影响。这些更改仅在随后的连接会话中生效。对动态全局特权的更改会立即生效。有关静态和动态特权之间差异的信息,请参阅静态与动态特权。Static global privileges and passwords are unaffected for a connected client. These changes take effect only in sessions for subsequent connections. Changes to dynamic global privileges apply immediately. For information about the differences between static and dynamic privileges, see Static Versus Dynamic Privileges.)
会话中活动角色集的更改会立即生效,但仅对该会话有效。SET
ROLE语句执行会话角色的激活和停用(参见第 15.7.1.11 节,“SET ROLE 语句”)。Changes to the set of active roles within a session take effect
immediately, for that session only. The SET
ROLE statement performs session role activation and
deactivation (see Section 15.7.1.11, “SET ROLE Statement”).
如果服务器使用 --skip-grant-tables 选项启动,它不会读取授权表或实施任何访问控制。任何用户都可以连接并执行任何操作,这是不安全的。 要使已这样启动的服务器读取表并启用访问检查,请刷新权限。If the server is started with the
--skip-grant-tables option, it does
not read the grant tables or implement any access control. Any
user can connect and perform any operation, which is
insecure. To cause a server thus started to read the
tables and enable access checking, flush the privileges.