42

I want to dump my database along the table schema and the table data also using the unix command line .

I used .

mysqldump -d -u root  -p frontend > frontend.sql

But above command is dumping only schema not the data from the database .

Please help me out how can i dump the database along the data also.

masterofdestiny
  • 2,751
  • 11
  • 28
  • 40
  • 3
    What you want is `mysqldump`. – fge Dec 24 '12 at 15:01
  • 9
    -d from man mysql dump `Do not write any table row information (that is, do not dump table contents). This is useful if you want to dump only the CREATE TABLE statement for the table (for example, to create an empty copy of the table by loading the dump file). ` – Jonathan de M. Dec 24 '12 at 15:11

7 Answers7

48
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

This will do,

If your requirement is to dump data alone then go for this,

To export to file (data only)

mysqldump -u [user] -p[pass] --no-create-db --no-create-info mydb > mydb.sql
Mariappan Subramanian
  • 9,527
  • 8
  • 32
  • 33
  • @masterofdestiny can you try this and get back to me if you face any issues – Mariappan Subramanian Dec 24 '12 at 15:13
  • if your database engine is InnoDB, you will prefer to use `--single-transaction` option. Read more [here](http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html). – FelikZ Dec 03 '13 at 10:16
  • I guess this method create sql with only create table statements without **create dataabse statement**. – EightT Oct 21 '22 at 16:08
21

backup: #

mysqldump -u root -p[password] [database_name] > dumpfilename.sql

restore:#

mysql -u root -p[password] [database_name] < dumpfilename.sql

[ref:] http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/

Raghvendra Parashar
  • 3,883
  • 1
  • 23
  • 36
14

You just need to remove -d from your mysqldump command

Bennet Joseph
  • 308
  • 3
  • 6
3

mysqldump offers plenty of options to build a proper backup from your database:

mysqldump [options] db_name [tbl_name ...]
mysqldump [options] --databases db_name ...
mysqldump [options] --all-databases

Here you can find more detail about how to mysqldump:

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

Nima Soroush
  • 12,242
  • 4
  • 52
  • 53
1

You're missing --no-data=False

e.g.

mysqldump -d -u root frontend --no-data=False -p > frontend.sql

ktang
  • 349
  • 2
  • 10
0

To restore database from .sql dumpfile

mysql -u [yourusername] -p [password] [nameofthedatabase] < /pathtoyoursqldumpfile.sql

Use mysqldump to create backup from database.

mysqldump -u [yourusername] -p [password] [nameofthedatabase] > /pathtoyoursqldumpfile.sql

-2

I think the command you would need will be mysqldump. Try the following:

mysqldump -u root -p -h localhost frontend < frontend.sql
  • Why is `frontend.sql` directed to stdin? Does `mysqldump` read from stdin? – eggyal Dec 24 '12 at 15:03
  • please check updated i tried that but it is dumping only schema – masterofdestiny Dec 24 '12 at 15:04
  • 2
    the only bad thing with this answer is the direciton of the data redirection.. it should be ">", not "<".. > redirects the output from mysqldump into frontend.sql.. < READS the frontend.sql and redirects it to the stdin of mysqldump.. wich wil do nothing with it. – KnF Jul 10 '15 at 16:13