Mysql Rename Multiple tables with a pattern

前端 未结 4 1635
孤街浪徒
孤街浪徒 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条回答
  •  猫巷女王i
    2021-01-28 15:30

    A slight modification on @ravnur's answer:

    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_', 'blog_')) name
        FROM information_schema.tables t
        WHERE table_name like 'wp_%'
    ) v;
    

    Useful when you want to rename your Wordpress tables from the default prefix of wp_ to blog_ (for example). Copy and paste the output of that command into the mysql shell or phpMyAdmin.

提交回复
热议问题