[翻译向] 当flush privileges生效时

#前言:

最近频繁在mysql权限控制这里栽跟斗,在翻阅了一些资料之后,简单地翻译一下官网关于flush privileges的描述,抛砖引玉。
 

#翻译正文:

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.

如果mysqld服务未使用--skip-grant-tables选项启动,mysql会在启动过程中将权限表的所有内容读取到内存中。此时,内存中的表将对访问控制生效。

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. Examples include GRANT, REVOKE, SET PASSWORD, and RENAME USER.

如果你不直接使用账号管理语句修改权限表,mysql服务会注意到这些改动并立即将其加载到内存当中。账号管理语句包括GRANT, REVOKE, SET PASSWORD, RENAME USER四个。

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!

如果你直接使用INSERT, UPDATE, DELETE(DELETE不推荐使用)修改权限表,除非你重新加载这个表,或者重启数据库,这些操作是不会影响权限检查的。因此,如果你修改了权限表但是忘记重新加载它们,直到你重启数据库,这个修改都是无效的。这可能会让你发现,为什么你命名修改了,但是没生效!

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.

为了告诉服务器重新加载权限表,需要执行一个刷新权限的命令。我们可以在数据库中执行FLUSH PRIVILEGES语句,或者在命令行中执行mysqladmin flush privileges或者mysqladmin reload命令。

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.

  • Database privilege changes take effect the next time the client executes a USE *db_name* statement.

**Note**

**Client applications may cache the database name; thus, this effect may not be visible to them without actually changing to a different database.**
  • Global privileges and passwords are unaffected for a connected client. These changes take effect only in sessions for subsequent connections.

每次权限表的加载都会对会话有以下影响:

  • 表级和行级的权限会在下次会话连接中改变

  • 数据库级的权限将会在下次USE DB_NAME后改变。

    注意:由于客户端存在缓存,如果不是真的切换数据库,此条改变可能不易被察觉。

  • 在同一个连接中,全局权限和密码不发生改变。只有开启新的会话时,才会生效。

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.

如果会话以--skip-grant-tables选项启动,它不会读取权限表,也没有相关访问控制的权限。任何人可以通过--skip-grant-tables进行连接和操作,这是不安全的。如果要从服务器开始读取权限表并保证访问检查,请刷新权限。

# 总结:

  1. flush privileges命令的作用是,使得在磁盘空间的修改写入到内存中,使其立即生效。
  2. 适合使用flush privileges的命令:INSERT、UPDATE、DELETE
  3. 不适合或不需要使用flush privileges的命令:GRANT、REVOKE、SET PASSWORD、RENAME USER
  4. 在相关改动之后(尤其是GRANT、REVOKE两箱操作,十分危险),千万不要,不要,不要轻易退出现有连接,否则就有你哭的了!

#后记

链接地址,摘自官网:
privileges changeshttps://dev.mysql.com/doc/refman/5.7/en/privilege-changes.html)

猜你喜欢

转载自www.cnblogs.com/young233/p/11863777.html
今日推荐