MySQL 重命名mysql数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13643802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rename mysql database?
提问by Ramesh Moorthy
How can I rename the MySQL database name using query?
如何使用查询重命名 MySQL 数据库名称?
I tried rename
database via phpmyadmin and getting the following error,
我rename
通过 phpmyadmin尝试数据库并收到以下错误,
SQL query:
RENAME DATABASE test TO test_bkp
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATABASE test To test_bkp' at line 1
回答by Lucas Arrefelt
In phpmyadmin you can just click on your database, then go to the Operations tab which lets you rename it.
在 phpmyadmin 中,您只需单击您的数据库,然后转到“操作”选项卡即可重命名它。
回答by Salman A
It says herethat:
它在这里说:
This statement was added in MySQL 5.1.7 but was found to be dangerous and was removed in MySQL 5.1.23. It was intended to enable upgrading pre-5.1 databases to use the encoding implemented in 5.1 for mapping database names to database directory names (see Section 9.2.3, “Mapping of Identifiers to File Names”). However, use of this statement could result in loss of database contents, which is why it was removed. Do not use RENAME DATABASE in earlier versions in which it is present.
该语句是在 MySQL 5.1.7 中添加的,但被发现是危险的,并在 MySQL 5.1.23 中删除。它旨在支持升级 5.1 之前的数据库以使用 5.1 中实现的编码将数据库名称映射到数据库目录名称(请参阅第 9.2.3 节,“标识符到文件名的映射”)。但是,使用此语句可能会导致数据库内容丢失,这就是它被删除的原因。不要在存在 RENAME DATABASE 的早期版本中使用它。
You can import all data into a new database then delete the old one.
您可以将所有数据导入新数据库,然后删除旧数据库。
It is also possible to use the RENAME TABLE
statement using same from/to table name but different from/to database. There are a few catches.
也可以使用RENAME TABLE
使用相同 from/to 表名但不同 from/to 数据库的语句。有几个问题。
CREATE DATABASE `test_bkp`;
RENAME TABLE
`test`.`table1` TO `test_bkp`.`table1`,
`test`.`table2` TO `test_bkp`.`table2`,
`test`.`table3` TO `test_bkp`.`table3`;
回答by joedborg
It's been disabled by the developers. See http://dev.mysql.com/doc/refman/5.1/en/rename-database.html
它已被开发人员禁用。见http://dev.mysql.com/doc/refman/5.1/en/rename-database.html
Adding to this, I'd use a copy (then delete) rather than a rename. Have a look at Cloning a MySQL database on the same MySql instance
除此之外,我会使用副本(然后删除)而不是重命名。看看在同一个 MySql 实例上克隆 MySQL 数据库
回答by Alex2php
You can do this in MySQL < 5.1.23 with
您可以在 MySQL < 5.1.23 中使用
RENAME {DATABASE | SCHEMA} db_name TO new_db_name;
In later versions have a look at
在以后的版本中看看
回答by Amado
in wamp server click on databases then choose your database from header menu choose operations make the new name it will rename the database but actually it create a new database copy all the data then drop the old data base
在 wamp 服务器中单击数据库然后从标题菜单中选择您的数据库选择操作使新名称它会重命名数据库但实际上它创建一个新数据库复制所有数据然后删除旧数据库
回答by Manoj kumar
- Export current database.
- create a new database with a name you want.
- import old database file on the new database.
- 导出当前数据库。
- 使用您想要的名称创建一个新数据库。
- 在新数据库上导入旧数据库文件。
回答by Precious Tom
Well, it's possible to rename your database but here's the logic behind the rename option.
好吧,可以重命名您的数据库,但这里是重命名选项背后的逻辑。
1. Xampp creates a new database with the name
2. Xampp copies all table and data in it from the previous database
3. Xampp migrates data to the new database table and drops the previous database
Steps to rename Database
重命名数据库的步骤
1. Click the Operations option in the nav pane
2. Find the ' Rename database to ' Spot, and input new name in the input field
3. Tick the ' Adjust privileges ' checkbox
4. Click go
I hope this works! :)
我希望这有效!:)
回答by Clark Superman
Ok, so if the rename option doesn't show, here a quick way of cloning a database using phpMyAdmin:
好的,如果重命名选项没有显示,这里有一种使用 phpMyAdmin 克隆数据库的快速方法:
- Open the database you want to copy
- Click the Operations tab.
- where it says "Copy database to:" type in the name of the new database. Select "structure and data" to copy everything or "Structure only" Check the box "CREATE DATABASE before copying" to create a new database. Check the box "Add AUTO_INCREMENT value." Click on the Go button to proceed. NB before deleting the old database, make sure that passwords have also copied over.
- 打开要复制的数据库
- 单击操作选项卡。
- 在它说“将数据库复制到:”的地方输入新数据库的名称。选择“结构和数据”复制所有内容或“仅结构”选中“复制前创建数据库”框以创建新数据库。选中“添加 AUTO_INCREMENT 值”框。单击“开始”按钮继续。注意在删除旧数据库之前,请确保密码也已复制过来。
回答by Hamid
you can export your databse table, create a new one and import table to the new database! also you can rename your data base using phpmyadmin by selecting your database and click on operations tab and rename your database! the last and not recommended way is create a new databse and use this, but you may lost your data!
您可以导出数据库表,创建一个新表并将表导入新数据库!您也可以使用 phpmyadmin 通过选择您的数据库并单击操作选项卡并重命名您的数据库来重命名您的数据库!最后一种不推荐的方法是创建一个新的数据库并使用它,但您可能会丢失数据!
CREATE DATABASE new_db_name / DROP DATABASE old_db_name