45

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. Commented 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). Commented Dec 24, 2012 at 15:11

7 Answers 7

51
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 
Sign up to request clarification or add additional context in comments.

3 Comments

@masterofdestiny can you try this and get back to me if you face any issues
if your database engine is InnoDB, you will prefer to use --single-transaction option. Read more here.
I guess this method create sql with only create table statements without create dataabse statement.
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/

Comments

18

You just need to remove -d from your mysqldump command

4 Comments

I was struggling to find this answer which just worked.
thank you for the comment
That's the solution! +1
thank you for the comment
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

Comments

1

You're missing --no-data=False

e.g.

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

Comments

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

Comments

-3

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

mysqldump -u root -p -h localhost frontend < frontend.sql 

3 Comments

Why is frontend.sql directed to stdin? Does mysqldump read from stdin?
please check updated i tried that but it is dumping only schema
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.