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.

2
  • 3
    What you want is mysqldump.
    – fge
    Dec 24, 2012 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). Dec 24, 2012 at 15:11

7 Answers 7

50
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
3
  • @masterofdestiny can you try this and get back to me if you face any issues Dec 24, 2012 at 15:13
  • if your database engine is InnoDB, you will prefer to use --single-transaction option. Read more here.
    – FelikZ
    Dec 3, 2013 at 10:16
  • I guess this method create sql with only create table statements without create dataabse statement.
    – EightT
    Oct 21, 2022 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/

14

You just need to remove -d from your mysqldump command

2
  • 1
    I was struggling to find this answer which just worked.
    – Siva Tumma
    Oct 9, 2022 at 13:57
  • 1
    That's the solution! +1 Jan 9 at 15:31
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

1

You're missing --no-data=False

e.g.

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

1
  • Yeah that is the ideal answer. thank you
    – PHPFan
    Aug 27, 2022 at 7:56
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
3
  • Why is frontend.sql directed to stdin? Does mysqldump read from stdin?
    – eggyal
    Dec 24, 2012 at 15:03
  • please check updated i tried that but it is dumping only schema Dec 24, 2012 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, 2015 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.