如何更改 MySQL 中数据库名称的大小写?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1708651/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:28:02  来源:igfitidea点击:

How can I change case of database name in MySQL?

mysqldatabaserename

提问by Rachel

My Database name is SPMand I want to change it to spm(small letters).

我的数据库名称是SPM,我想将其更改为spm(小写字母)。

I tried using

我尝试使用

RENAME DATABASE SPM TO spm;

, but I am getting the following error message:

,但我收到以下错误消息:

ERROR 1064 (42000): 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 SPM to spm' at line 1

My server version: 5.0.45

我的服务器版本:5.0.45

回答by Peter Lindqvist

There is no database command to do it. You basically have to do it outside the database. Below are some references outlining possible solutions. It has been answered pretty good in this question

没有数据库命令可以做到这一点。您基本上必须在数据库之外进行。以下是一些概述可能解决方案的参考资料。这个问题已经回答的很好了

This is probably what it should look like in your case

这可能就是你的情况

mysqladmin create spm
mysqldump SPM | mysql spm

After you have verified that everything is in order you can drop the original database.

在您确认一切正常后,您可以删除原始数据库。

drop database SPM

References Rename database 1/ Rename database 2

参考文献 重命名数据库 1/重命名数据库 2

[Note on "RENAME DATABASE" command: This statement was added in MySQL 5.1.7 but was found to be dangerous and was removed in MySQL 5.1.23.]

[关于“ RENAME DATABASE”命令的注意事项:该语句是在 MySQL 5.1.7 中添加的,但被发现是危险的,并在 MySQL 5.1.23 中被删除。]

回答by krishna

RENAME {DATABASE | SCHEMA} db_name TO new_db_name;

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 . However, use of this statement could result in loss of database contents, which is why it was removed. Do not use RENAME DATABASEin earlier versions in which it is present.

该语句是在 MySQL 5.1.7 中添加的,但被发现是危险的,并在 MySQL 5.1.23 中删除。它旨在支持升级 5.1 之前的数据库以使用 5.1 中实现的编码将数据库名称映射到数据库目录名称。但是,使用此语句可能会导致数据库内容丢失,这就是它被删除的原因。不要RENAME DATABASE在存在它的早期版本中使用。

To perform the task of upgrading database names with the new encoding, use ALTER DATABASE db_name UPGRADE DATA DIRECTORY NAMEinstead.

要使用新编码执行升级数据库名称的任务,请ALTER DATABASE db_name UPGRADE DATA DIRECTORY NAME改用。

回答by MightyE

Use mysql_dump to dump out the database contents of the old schema (it produces SQL output, and can include all the object CREATE statements), switch to the new schema, and execute that script mysql> . dump.sql

使用 mysql_dump 转储旧模式的数据库内容(它产生 SQL 输出,并且可以包含所有对象 CREATE 语句),切换到新模式,并执行该脚本 mysql> . dump.sql

If it's a large database, this may take a while, but it's the safest way to do it (make sure you suspend any applications using the database while the conversion process is going on).

如果它是一个大型数据库,这可能需要一段时间,但这是最安全的方法(确保在转换过程进行时暂停任何使用该数据库的应用程序)。

Delete the old schema when you're satisfied that everything worked.

当您对一切正常工作感到满意时,删除旧模式。

回答by dstibbe

This is done with a RENAME DATABASEstatement:

这是通过一个RENAME DATABASE语句完成的:

RENAME DATABASE old_db_name TO new_db_name;

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

该语句是在 MySQL 5.1.7 中添加的,但被发现是危险的,并在 MySQL 5.1.23 中删除。

回答by Pritam Chaudhari

You can change your database name using Mysql User interface

您可以使用 Mysql 用户界面更改数据库名称

Step1: First of all Go to localhost/phpmyadmin/ and click on your database

Step1:首先进入localhost/phpmyadmin/并点击你的数据库

Step2: Click on Opertaion tab

步骤 2:单击“操作”选项卡

Step3: Enter new database name into (Rename database to) textfield

步骤 3:在 (Rename database to) 文本字段中输入新的数据库名称

Step4: Click on Go Buttton

第四步:点击前往按钮

回答by silent

Use rename databasecommand.

使用重命名数据库命令。

You can also try to stop your mysql server and rename a folder that contains your db data to the name you prefer. Then start your server and check the grants - they might still contain references to your old database name.

您也可以尝试停止您的 mysql 服务器并将包含您的 db 数据的文件夹重命名为您喜欢的名称。然后启动您的服务器并检查授权 - 它们可能仍包含对旧数据库名称的引用。