how does one rename a schema in MySQL

前端 未结 3 459
小鲜肉
小鲜肉 2020-12-14 15:02

Hi I am using mysql 5.0.x

How do I rename a schema?

相关标签:
3条回答
  • 2020-12-14 15:38

    Under 5.0, you need to dump the database and reload it into a new database with a new name. If you upgrade to 5.1, you can lookup and use the RENAME DATABASE command.

    0 讨论(0)
  • 2020-12-14 15:41

    Don't use RENAME DATABASE!!!

    Early 5.1 versions had this command but it's been removed since it can corrupt data (reference).

    The only way at present is

    mysqladmin create new_db_name
    mysqldump db_name | mysql new_db_name
    

    as referred to here

    Edit: Obviously this answer will become dated once this gets fixed.

    0 讨论(0)
  • 2020-12-14 15:59

    It's easy. Export the database to file, then import it again in workbench you can specify the name of the db there.

    In workbench go to the Server tab, select Data Export. Select the DB you want to rename, select export to self contained file, and give the file a name. make sure you have Dump structure and Data selected. Hit start export.

    In workbench go to the Server tab, select Data Import. Select Import from self contained file. Select the file you created. In the section titled Default Schema to be imported to click the new option. Enter the new name for the DB, then select it from the drop down. Hit Start Import.

    Voila, new database with the name you want plus all the tables and data from the old one.

    0 讨论(0)
提交回复
热议问题