How to export mysql database structure only on command line, but export some data of specific tables from specified in list

I want to export a MySQL database through the command line with the following two conditions, as shown below,

  • Only export database table structure.
  • But during the data export, I want to export the specified data and the table structure that are mentioned in the command.

I have a database that contains 60 tables, and of these, one table with a name Countrycontains static values. Therefore, I want to export my data also to the exported file, and the rest of the tables contain only the structure in the exported file.

Can someone suggest me a MySQL command to dump a database based on the above conditions?

+4
source share
2 answers

First method:

mysqldump --no-data -h <host> -u <username> -p<password> <database> > tables.sql

This will delete the database table structures in the file tables.sql.

The parameter --no-dataindicates that the contents of the table are not flushed.

Second method:

(This can be useful if you want a more generated file .sqlin batch processing.)

  • Use the command show create tableto see the actual command to create the table.
  • Create a Bash script that executes this MySQL command for each table that you want to export. Perform output from show create table <table_name>to a text file.
+1

, .

mysqldump -u root -p password --no-data --ignore-table=db_name.tbl_name db_name > db_name.sql

.

mysqldump -u root -p password db_name tbl_name >> db_name.sql

.

+1

Source: https://habr.com/ru/post/1681755/


All Articles