A novel way for MySQL to modify the database name _mysql

Source: Internet
Author: User

MySQL introduced a rename database operation in 5.1, but did not support this command after MySQL5.1.23. Can be said to be an experimental function, not in the production support (mysql-5.1 release in mysql-5.1.30), then in production we sometimes for the pursuit of perfection need to change the library name. How to operate it?
This provides an alternative approach.

1. Create a new library name:

Copy Code code as follows:

Mysql>create database db_v2;

2. Generate Rename statements , migration from OLDDB, I am here olddb sbtest;
Copy Code code as follows:
Mysql>select concat ("Rename table", Table_schema, ".", TABLE_NAME, "to DB_V2.", TABLE_NAME, ";") into outfile '/tmp/rename_to_db_v2.sql ' from information_schema.tables where table_schema= ' sbtest ';

3. Execute the generated SQL
Copy Code code as follows:
Mysql>source/tmp/rename_to_db_v2.sql

It's as simple as it can be done.
Good luck!

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.