omprakash sharma
omprakash sharma

Reputation: 81

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

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

  1. Export database tables structure only.
  2. But at the time of Exporting data, I want to export specified table data and structure both that are mention in command.

I have a database which contains 60 tables, and from them, one table named Country contains the static values. So I want to export its data too in the exported file, and rest of the tables contain only structure in exported file.

Can any one suggest me MySQL command to dump the database based on above conditions?

Upvotes: 4

Views: 1588

Answers (2)

Onkar
Onkar

Reputation: 49

I think you'll need to fire 2 separate commands for that.

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

Above query will dump all the structure of database without your country table's structure and data.

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

And this one will dump Country table's structure and data into the same file.

Upvotes: 0

Paul-Beyond
Paul-Beyond

Reputation: 1737

First method:

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

This will dump your database table structures into the file tables.sql.

The --no-data option specifies that table content is not dumped.

Second method:

(This can be useful if you want to more with the generated .sql file in batch processing.)

  • Use the show create table command to see the actual command to create a table.
  • Create a Bash script that executes that MySQL command for every table that you want to export. Pipe the output from show create table <table_name> to a text file.

Upvotes: 1

Related Questions