Home > Database > Mysql Tutorial > body text

How to change the name of mysql database

coldplay.xixi
Release: 2020-10-19 10:59:30
Original
15110 people have browsed it

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 mysql database

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;
Copy after login

Get the table names of all source libraries

use information_schema;
select table_name from TABLES where TABLE_SCHEMA=’srcdb’;
Copy after login

Then follow the following commands to modify one by one

rename table srcdb.[tablename] to trgdb.[tablename];
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!