我们如何在MySQL 5.0中重命名数据库名称 [英] How can we rename the database name in MySQL 5.0
问题描述
我正在使用MySQL 5.0.
我已经创建了一个名为accounts
的数据库,但是现在我想将该数据库名称更改为FinanceAccounts
.
I have created a database named accounts
, but now I want to change the database name to FinanceAccounts
.
如何在MySQL 5.0
中更改数据库名称?
How can I change the database name in MySQL 5.0
?
推荐答案
我认为只有一种方法(除了重命名MySQL数据目录中的目录(对于InnoDB表而言,该目录将失败):
I think there is only one way (besides renaming directory in the MySQL datadir which will fail for InnoDB tables):
- 创建新数据库(使用新名称)
- 对旧数据库进行转储
- 将转储的数据导入新数据库
- 删除旧数据库
要创建新的数据库,请执行以下操作:
To create the new DB:
mysql> CREATE DATABASE new_database;
要创建旧数据库的转储,请执行以下操作:
To create the dump of the old DB:
mysqldump -u "your_username" -p --lock-tables old_database > old_database_dump.sql
要将转储的数据导入新数据库:
To import dumped data into the new DB:
mysql -u "your username" -p new_database < old_database_dump.sql
要删除旧数据库,请执行以下操作:
To delete the old DB:
mysql> DROP DATABASE old_database;
请记住,您对旧数据库的权限也需要删除.请参阅此处以获取更多信息: 撤消MySQL数据库上所有用户的所有特权
Bear in mind that your permissions on the old DB will need to be deleted as well. See here for more info: Revoke all privileges for all users on a MySQL DB
从MySQL 5.1.7到MySQL 5.1.22,有一个RENAME {DATABASE | SCHEMA} db_name TO new_db_name;
命令,但是由于过于危险,该命令已在MySQL 5.1.23中删除.
MySQL 5.1.7 to MySQL 5.1.22 had a RENAME {DATABASE | SCHEMA} db_name TO new_db_name;
command but this one has been removed in MySQL 5.1.23 for being too dangerous.
这篇关于我们如何在MySQL 5.0中重命名数据库名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!