最新消息: 新版网站上线了!!!

mysql改更数据库的前缀

  1. SET @database   = "database_name"
  2. SET @old_prefix = "old_prefix_"
  3. SET @new_prefix = "new_prefix_"
  4.   
  5. SELECT 
  6.     concat( 
  7.         "RENAME TABLE "
  8.         TABLE_NAME, 
  9.         " TO "
  10.         replace(TABLE_NAME, @old_prefix, @new_prefix), 
  11.         ';' 
  12.     ) AS "SQL" 
  13. FROM information_schema.TABLES WHERE TABLE_SCHEMA = @database; 

实例
 

  1. SELECT 
  2.     CONCAT( 
  3.         "RENAME TABLE "
  4.         TABLE_NAME, 
  5.         " TO "
  6.         REPLACE(TABLE_NAME, 'item_''haha_'), 
  7.         ';' 
  8.     ) AS "SQL" 
  9. 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改更数据库的前缀