Mysql Rename Multiple tables with a pattern

前端 未结 4 1634
孤街浪徒
孤街浪徒 2021-01-28 15:00

I know how to run

RENAME TABLE onetable_test TO onetable;

But is there a method to rename many tables with a pattern and don\'t write a lot of

4条回答
  •  面向向阳花
    2021-01-28 15:22

    I wanted to update what worked for me since this post is pretty old. I needed to add the ` mark before and after the table names. And don't forget to add the last ; because this can sometimes throw a syntax error.

    SET group_concat_max_len=5000;
    SELECT group_concat(v.name separator '; ')
    FROM (
        SELECT concat('RENAME TABLE `', t.table_name, '` TO `', replace(t.table_name, 'wp_', 'wplocal_'), '`') name
        FROM information_schema.tables t
        WHERE table_name like 'wp_%'
    ) v;
    

提交回复
热议问题