Renaming a database in MySQL

Source: Internet
Author: User
MySQL official documentation mentions ALTERDATABASEdb_nameUPGRADEDATADIRECTORYNAME, which is used to display the database name after upgrade of version 5.0 and version 5.1.

The MySQL official document mentions alter database db_name upgrade data directory name, which is used to display the database name after UPGRADE 5.0 and 5.1.

It is not a labor-saving task. If your MySQL version is 5.1.7 and earlier than 5.1.23, you can use the following simple method:
RENAME {DATABASE | SCHEMA} db_name TO new_db_name;

However, this method is not reliable and may cause data loss. It is not recommended. Description of this official document ():
However, use of this statement cocould 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.

This statement is not safe and cannot be used in Versions later than 5.1.23.

In addition, there are some trade-offs. In general, we use mysqldump to export data, create a new database, import data, and drop the old database.

Mysqladmin create spm
Mysqldump SPM | mysql spm

If you have phpmyadmin, you can click the "operation" tab, which is "rename the Database", with 1000 words omitted here.

PS: the MySQL official document mentions alter database db_name upgrade data directory name, which is used to solve the problem of displaying the database name after UPGRADE 5.0 and 5.1, and is not the same as renaming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.