[英]How to delete multiple events in mysql 8.0 database ? it was working in 5.7 but not in 8.0?
Is there any possibilities to drop multiple events using single query ? 是否有可能使用单个查询删除多个事件? I know, we can get list of events using show events and drop single event with there name.
我知道,我们可以使用show events获取事件列表,并删除带有名称的单个事件。
In mysql 5.7 or lowest version it is possible but i am using mysql 8.0. 在mysql 5.7或最低版本中可以,但是我正在使用mysql 8.0。
I suggest using MySQL Shell - for a one off, you can use (using Python mode): 我建议使用MySQL Shell-一次可以使用(使用Python模式):
mysqlsh> \py
mysql-py> i_s = session.get_schema("information_schema")
mysql-py> events = i_s.EVENTS \
-> .select("sys.quote_identifier(EVENT_SCHEMA) AS EventSchema", "sys.quote_identifier(EVENT_NAME) AS EventName") \
-> .where("EVENT_SCHEMA = 'db1'").execute().fetch_all();
mysql-py> events
[
[
"`db1`",
"`event1`"
],
[
"`db1`",
"`event2`"
],
[
"`db1`",
"`event``3`"
]
]
mysql-py> sql_fmt = "DROP EVENT {0}.{1}"
mysql-py> for event in events:
-> print(sql_fmt.format(*event))
-> session.sql(sql_fmt.format(*event)).execute()
->
DROP EVENT `db1`.`event1`
DROP EVENT `db1`.`event2`
DROP EVENT `db1`.`event``3`
Query OK, 0 rows affected (0.0038 sec)
For a more throughout explanation and examples of creating a more general purpose utility, see also https://mysql.wisborg.dk/2018/12/02/mysql-8-drop-several-stored-events-procedures-or-functions/ . 有关创建更多通用工具的更全面的说明和示例,另请参见https://mysql.wisborg.dk/2018/12/02/mysql-8-drop-several-stored-events-procedures-or-functions / 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.