大道至简,知易行难
广阔天地,大有作为

MySQL批量修改视图的ALGORITHM、DEFINER、SECURITY定义

对于MySQL而言,视图的定义中有三个重要的参数:

援引官方文档:

The optional ALGORITHM clause for CREATE VIEW or ALTER VIEW is a MySQL extension to standard SQL. It affects how MySQL processes the view. ALGORITHM takes three values: MERGETEMPTABLE, or UNDEFINED.

  • For MERGE, the text of a statement that refers to the view and the view definition are merged such that parts of the view definition replace corresponding parts of the statement.
  • For TEMPTABLE, the results from the view are retrieved into a temporary table, which then is used to execute the statement.
  • For UNDEFINED, MySQL chooses which algorithm to use. It prefers MERGE over TEMPTABLE if possible, because MERGE is usually more efficient and because a view cannot be updatable if a temporary table is used.
  • If no ALGORITHM clause is present, the default algorithm is determined by the value of the derived_merge flag of the optimizer_switch system variable.

The DEFINER and SQL SECURITY clauses determine which MySQL account to use when checking access privileges for the view when a statement is executed that references the view. The valid SQL SECURITY characteristic values are DEFINER (the default) and INVOKER. These indicate that the required privileges must be held by the user who defined or invoked the view, respectively.

If the DEFINER clause is present, the user value should be a MySQL account specified as 'user_name'@'host_name'CURRENT_USER, or CURRENT_USER().

我们可以通过如下的SQL生成批量将视图的SQL SECURITY修改为INVOKER的SQL:

我们可以通过如下的SQL生成批量修改视图DEFINER的SQL:

参考资料:
1、https://dev.mysql.com/doc/refman/8.0/en/create-view.html
2、https://dev.mysql.com/doc/refman/8.0/en/alter-view.html
3、https://dev.mysql.com/doc/refman/8.0/en/view-algorithms.html

转载时请保留出处,违法转载追究到底:进城务工人员小梅 » MySQL批量修改视图的ALGORITHM、DEFINER、SECURITY定义

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址