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!