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

前端 未结 30 2795
余生分开走
余生分开走 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:05

    Emulating the missing RENAME DATABASE command in MySQL:

    1. Create a new database
    2. Create the rename queries with:

      SELECT CONCAT('RENAME TABLE ',table_schema,'.',table_name,
          ' TO ','new_schema.',table_name,';')
      FROM information_schema.TABLES
      WHERE table_schema LIKE 'old_schema';
      
    3. Run that output

    4. Delete old database

    It was taken from Emulating The Missing RENAME DATABASE Command in MySQL.

提交回复
热议问题