MySQL database name modification tutorial, mysql database name modification tutorial
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; mysql> create database db_v2;
2. 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'; 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 mysql> source/tmp/rename_to_db_v2. SQL
That's easy.
Good luck!