Reputation: 81
I want to export MySQL database through command line with following two conditions as below,
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
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
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.)
show create table
command to see the actual command to create a table.show create table <table_name>
to a text file.Upvotes: 1