Is there a way to tell if MySQL has been started with skip-grant-tables within mysql? I can't find anything in show variables
有没有办法判断MySQL是否已经开始使用MySQL中的skip-grant表?在显示变量中我找不到任何东西。
I'd like to add a guard to a startup sql script to prevent UDF functions from trying to be created when they can't be (e.g. the docker startup is running setup, etc)
我想为启动sql脚本添加一个保护,以防止在无法创建UDF函数时尝试创建它们(例如,docker启动正在运行setup等)
Thanks
谢谢
1 个解决方案
#1
2
There doesn't seem to exist a variable to determine that.
似乎不存在一个变量来确定它。
The following stored procedure can give you some ideas:
下面的存储过程可以给您一些建议:
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)
#1
2
There doesn't seem to exist a variable to determine that.
似乎不存在一个变量来确定它。
The following stored procedure can give you some ideas:
下面的存储过程可以给您一些建议:
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)