TIPS: MySQL database name change operation author: Wu Bingxi Source: http://www.mysqlsupport.cn/Contact Information: wubingxi # 163.com reprint please indicate/translator and source, and cannot be used for commercial purposes, offenders must investigate.
MySQL introduced a rename database operation in MySQL 5.1, but does not support this command after MySQL5.1.23. It can be said that it is an experimental function, not supported in production (mysql-5.1 release in mysql-5.1.30), so in production we sometimes need to change the library name to the pursuit of perfection. How can this problem be solved?
Here is a work und.
1. create a new database name:
Mysql> create database db_v2;
- Generate the rename statement and migrate it from olddb. here I will use sbtest in olddb;
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
Mysql> source/tmp/rename_to_db_v2. SQL
That's easy. Good luck!