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

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

    The simple way

    Change to the database directory:

    cd /var/lib/mysql/
    

    Shut down MySQL... This is important!

    /etc/init.d/mysql stop
    

    Okay, this way doesn't work for InnoDB or BDB-Databases.

    Rename database:

    mv old-name new-name
    

    ...or the table...

    cd database/
    
    mv old-name.frm new-name.frm
    
    mv old-name.MYD new-name.MYD
    
    mv old-name.MYI new-name.MYI
    

    Restart MySQL

    /etc/init.d/mysql start
    

    Done...

    OK, this way doesn't work with InnoDB or BDB databases. In this case you have to dump the database and re-import it.

提交回复
热议问题