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

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

    Use these few simple commands:

    mysqldump -u username -p -v olddatabase > olddbdump.sql
    mysqladmin -u username -p create newdatabase
    mysql -u username -p newdatabase < olddbdump.sql
    

    Or to reduce I/O use the following as suggested by @Pablo Marin-Garcia:

    mysqladmin -u username -p create newdatabase
    mysqldump -u username -v olddatabase -p | mysql -u username -p -D newdatabase
    

提交回复
热议问题