- SET @database = "database_name";
- SET @old_prefix = "old_prefix_";
- SET @new_prefix = "new_prefix_";
- SELECT
- concat(
- "RENAME TABLE ",
- TABLE_NAME,
- " TO ",
- replace(TABLE_NAME, @old_prefix, @new_prefix),
- ';'
- ) AS "SQL"
- FROM information_schema.TABLES WHERE TABLE_SCHEMA = @database;
实例
- SELECT
- CONCAT(
- "RENAME TABLE ",
- TABLE_NAME,
- " TO ",
- REPLACE(TABLE_NAME, 'item_', 'haha_'),
- ';'
- ) AS "SQL"
- FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'test';
复制后执行 就ok了
RENAME TABLE catalog TO catalog;
RENAME TABLE employee TO employee;
RENAME TABLE haha_member TO haha_member;
RENAME TABLE item TO item;
RENAME TABLE op2mro445_commentmeta TO op2mro445_commentmeta;
RENAME TABLE page TO page;
RENAME TABLE page_history TO page_history;
RENAME TABLE tbl_makanan TO tbl_makanan;
转载请注明:谷谷点程序 » mysql改更数据库的前缀