How can I truncate all tables from a MySQL Database?

前端 未结 2 1591
忘了有多久
忘了有多久 2021-01-22 16:34

Is there any way to truncate all tables from a specific MySQL database name without using any other language than SQL? I mean no linux shell scripts. (why? because it will run o

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 17:06

    create procedure drop_tables_like(pattern varchar(255), db varchar(255))
    begin
    select @str_sql:=concat('drop table ', group_concat(table_name))
    from information_schema.tables
    where table_schema=db and table_name like pattern;
    
    prepare stmt from @str_sql;
    execute stmt;
    drop prepare stmt;
    end
    

    then call

    call drop_tables_like('%', 'dababase_name')
    

提交回复
热议问题