How to change the name of the MySQL database: first create the target library; then obtain the table names of all source libraries; finally modify them one by one according to the relevant commands, the code is [rename table srcdb.[tablename] to trgdb.[tablename] ]].
How to change the name of the mysql database:
1. If it is MyISAM, just modify the The name of the folder with that library name will be OK
2. If it is INNODB, it is actually impossible to modify the library name. RENAME DATABASE or ALTER DATABASE that are found online will not work
3. One method is more conservative, directly mysqldump the contents of the old library into the new library
4. There is another method similar to the above. First alter the storage engine of the table to MyISAM, and then Change the name of the library directory, and then change it back to INNODB.
5. The last method is better. Let’s write it in detail here.
Assume that the source library name is 'srcdb' and the target library name is 'trgdb'
First create the target library
create database trgdb;
Get the table names of all source libraries
use information_schema; select table_name from TABLES where TABLE_SCHEMA=’srcdb’;
Then follow the following commands to modify one by one
rename table srcdb.[tablename] to trgdb.[tablename];
Related free learning recommendations:mysql database(Video )
The above is the detailed content of How to change the name of mysql database. For more information, please follow other related articles on the PHP Chinese website!