我建议使用mysql shell-下面的示例使用python模式:
mysqlsh> \py
mysql-py> i_s = session.get_schema("information_schema")
mysql-py> functions = i_s.ROUTINES \
-> .select("sys.quote_identifier(ROUTINE_SCHEMA) AS RoutineSchema", "sys.quote_identifier(ROUTINE_NAME) AS RoutineName") \
-> .where("ROUTINE_SCHEMA = 'db1' AND ROUTINE_TYPE = 'FUNCTION'").execute().fetch_all()
mysql-py> functions
[
[
"`db1`",
"`func1`"
],
[
"`db1`",
"`func2`"
],
[
"`db1`",
"`func``3`"
]
]
mysql-py> for function in functions:
-> print(sql_fmt.format(*function))
-> session.sql(sql_fmt.format(*function)).execute()
->
DROP FUNCTION `db1`.`func1`
DROP FUNCTION `db1`.`func2`
DROP FUNCTION `db1`.`func``3`
Query OK, 0 rows affected (0.0684 sec)
有关更多讨论,请参见
https://mysql.wisborg.dk/2018/12/02/mysql-8-drop-several-stored-events-procedures-or-functions/
.