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

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

    Seems noone mentioned this but here is another way:

    create database NewDatabaseName like OldDatabaseName;
    

    then for each table do:

    create NewDatabaseName.tablename like OldDatabaseName.tablename;
    insert into NewDataBaseName.tablename select * from OldDatabaseName.tablename;
    

    then, if you want to,

    drop database OldDatabaseName;
    

    This approach would have the advantage of doing the entire transfer on server with near zero network traffic, so it will go a lot faster than a dump/restore.

    If you do have stored procedures/views/etc you might want to transfer them as well.

提交回复
热议问题