How do I quickly rename a MySQL database (change schema name)?

前端 未结 30 2409
余生分开走
余生分开走 2020-11-22 14:54

The MySQL manual at MySQL covers this.

Usually I just dump the database and reimport it with a new name. This is not an option for very big databases. Apparently

30条回答
  •  清酒与你
    2020-11-22 15:04

    Here is a quick way to generate renaming sql script, if you have many tables to move.

    SELECT DISTINCT CONCAT('RENAME TABLE ', t.table_schema,'.', t.table_name, ' TO ',     
    t.table_schema, "_archive", '.', t.table_name, ';' ) as Rename_SQL 
    FROM information_schema.tables t
    WHERE table_schema='your_db_name' ;
    

提交回复
热议问题