mysql copy all table structure and data of database to another database

To copy all table structures and data from one MySQL database to another, the following steps can be used:

  1. Create an empty database in the target database. For example, suppose you want to copy a database named olddb into a new database named newdb, you can use the following statement:
CREATE DATABASE newdb;
  1. Run the following command in any folder to export the entire database:
mysqldump -u username -p olddb > olddb.sql

This command will export the entire database named olddb and save it in a file named olddb.sql.

  1. Import the exported SQL file into the target database. The following commands can be used:
mysql -u username -p newdb < olddb.sql

This will create the same tables in the newdb database as the olddb database, including the table structure and data.

Note that if you only need to copy the table structure and not the data, you can add the --no-data option when exporting the SQL file as follows:

mysqldump -u username -p --no-data olddb > olddb.sql

This will export the table structure, but not the data. You can then use the commands in steps two and three to import the table structure into the target database.

Supongo que te gusta

Origin blog.csdn.net/nj0128/article/details/129733574
Recomendado
Clasificación