重命名mysql数据库? [英] Rename mysql database?

查看:81
本文介绍了重命名mysql数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用查询重命名MySQL数据库名称?

How can I rename the MySQL database name using query?

我通过phpmyadmin尝试了rename数据库并收到以下错误,

I tried rename database via phpmyadmin and getting the following error,

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

推荐答案

它说

此语句是在MySQL 5.1.7中添加的,但发现很危险 并已在MySQL 5.1.23中删除.旨在实现升级 5.1之前的数据库使用5.1中实现的编码进行映射 数据库名称到数据库目录名称(请参见第9.2.3节, 标识符到文件名的映射").但是,使用这个 语句可能导致数据库内容丢失,这就是为什么 去掉了.不要在以下版本的早期版本中使用RENAME DATABASE: 它存在.

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.

您可以将所有数据导入新数据库,然后删除旧数据库.

You can import all data into a new database then delete the old one.

还可以使用 RENAME TABLE 语句,使用与表名相同的表名,但与数据库的表名不同.有一些收获.

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.

CREATE DATABASE `test_bkp`;

RENAME TABLE 
`test`.`table1` TO `test_bkp`.`table1`,
`test`.`table2` TO `test_bkp`.`table2`,
`test`.`table3` TO `test_bkp`.`table3`;

这篇关于重命名mysql数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆