How can I change case of database name in MySQL?

前端 未结 6 920
迷失自我
迷失自我 2021-02-04 03:12

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

I tried using

RENAME DATABASE SPM TO spm;
相关标签:
6条回答
  • 2021-02-04 03:54

    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

    [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.]

    0 讨论(0)
  • 2021-02-04 03:56

    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

    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.

    0 讨论(0)
  • 2021-02-04 03:58

    You can change your database name using Mysql User interface

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

    Step2: Click on Opertaion tab

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

    Step4: Click on Go Buttton

    0 讨论(0)
  • 2021-02-04 04:00
    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 DATABASE in earlier versions in which it is present.

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

    0 讨论(0)
  • 2021-02-04 04:01

    This is done with a RENAME DATABASE statement:

    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.

    0 讨论(0)
  • 2021-02-04 04:02

    Use rename database command.

    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.

    0 讨论(0)
提交回复
热议问题