确定 MySQL 是否已使用 skip-grant-tables 启动

Determine if MySQL has been started with skip-grant-tables

有没有办法判断 MySQL 是否已在 mysql 中使用 skip-grant-tables 启动?我在 show variables

中找不到任何内容

我想在启动 sql 脚本中添加一个防护,以防止在无法创建 UDF 函数时尝试创建它们(例如 docker 启动是 运行 设置等)

谢谢

似乎不​​存在确定这一点的变量。

下面的存储过程可以给你一些思路:

DELIMITER //

DROP PROCEDURE IF EXISTS `_`.`skip_grant_tables`//

CREATE PROCEDURE `_`.`skip_grant_tables`(OUT `skip_grant` BOOL)
BEGIN
  DECLARE `skip_grant_text` TEXT;
  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  BEGIN
    GET DIAGNOSTICS CONDITION 1 `skip_grant_text` = MESSAGE_TEXT;
  END;
  SET `skip_grant` := 0;
  GRANT SELECT ON *.* TO ''@'';
  IF (`skip_grant_text` REGEXP '--skip-grant-tables option') THEN
    SET `skip_grant` := 1;
  END IF;
END//

DELIMITER ;

mysql> CALL `_`.`skip_grant_tables`(@`skip_grant_tables?`);
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @`skip_grant_tables?`;
+-----------------------+
| @`skip_grant_tables?` |
+-----------------------+
|                     1 |
+-----------------------+
1 row in set (0.00 sec)