How do I quickly rename a MySQL database (change s

2018-12-31 20:59发布

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 RENAME {DATABASE | SCHEMA} db_name TO new_db_name; does bad things, exist only in a handful of versions, and is a bad idea overall.

This needs to work with InnoDB, which stores things very differently than MyISAM.

30条回答
浮光初槿花落
2楼-- · 2018-12-31 21:43

I think the solution is simpler and was suggested by some developers. phpMyAdmin has an operation for this.

From phpMyAdmin, select the database you want to select. In the tabs there's one called Operations, go to the rename section. That's all.

It does, as many suggested, create a new database with the new name, dump all tables of the old database into the new database and drop the old database.

Enter image description here

查看更多
一个人的天荒地老
3楼-- · 2018-12-31 21:43

When you rename a database in PHPMyAdmin it creates a dump, then drops and recreates the database with the new name.

查看更多
梦寄多情
4楼-- · 2018-12-31 21:43

Steps :

  1. Hit http://localhost/phpmyadmin/
  2. Select your DB
  3. Click on Operations Tab
  4. There will be a tab as "Rename database to". Add new name and check Adjust privileges.
  5. Click on Go.

enter image description here

查看更多
回忆,回不去的记忆
5楼-- · 2018-12-31 21:44

MySQL does not support the renaming of a database through its command interface at the moment, but you can rename the database if you have access to the directory in which MySQL stores its databases. For default MySQL installations this is usually in the Data directory under the directory where MySQL was installed. Locate the name of the database you want to rename under the Data directory and rename it. Renaming the directory could cause some permissions issues though. Be aware.

Note: You must stop MySQL before you can rename the database

I would recommend creating a new database (using the name you want) and export/import the data you need from the old to the new. Pretty simple.

查看更多
情到深处是孤独
6楼-- · 2018-12-31 21:44

The simplest method is to use HeidiSQL software. It's free and open source. It runs on Windows and on any Linux with Wine (run Windows applications on Linux, BSD, Solaris and Mac OS X).

To download HeidiSQL, goto http://www.heidisql.com/download.php.

To download Wine, goto http://www.winehq.org/.

To rename a database in HeidiSQL, just right click on the database name and select 'Edit'. Then enter a new name and press 'OK'.

It is so simple.

查看更多
无与为乐者.
7楼-- · 2018-12-31 21:44

ALTER DATABASE is the proposed way around this by MySQL and RENAME DATABASE is dropped.

From 13.1.32 RENAME DATABASE Syntax:

RENAME {DATABASE | SCHEMA} db_name TO new_db_name;

This statement was added in MySQL 5.1.7, but it was found to be dangerous and was removed in MySQL 5.1.23.

查看更多
登录 后发表回答