Thursday, October 7, 2010

MySql Tutorial : mysqldump utility in mysql

The mysqldump client is a backup program o It can be used to dump a database or a collection of databases for backup or transfer to another SQL server (not necessarily a MySQL server). The dump typically contains SQL statements to create the table, populate it, or both. However, mysqldump can also be used to generate files in CSV, other delimited text, or XML format.


To take dump of a mysql table use below command
-------------------------------------------------------
~/mysql/bin/mysqldump -u root  database_name ORDERS > orders.txt

1.  command to dumb  only tables definitions , not the data “ use –d command”  if path is not set then you need to run that command from mysql/bin directory

./mysqldump -d -u root database_name  ORDERS , CLIENTS , COMPANY  > ~/tmp/test.database.sql

2. Command to recreate table from that file

mysql -u root database_name < ~/tmp/test.database.sql


hope this would be useful. if you have not read my other MySQL command tutorials , you can see it here

MySQL tutorial and commands part 2
MySQL tutorial and commands part 3
MySql Tutorial : mysqldump utility in mysql
MySQL tutorial and commands Part 1

How to manage transaction in MySQL




4 comments :

Anonymous said...

excellent work. Great Post,Amazing, marvelous, outstanding (take all other words you like) :-)

and finally, GREAT COPY-PASTE CONTENTS IN SIDE YOUR POST. TRY SOMETHING NEW YOURSELF & EXPRESS YOURSELF, DON'T INSPIRE FROM OTHER POST AND DO COPY PASTE MY FRIEND.

Javin @ OutOfMemoryError in Java said...

Thanks Anonymous, Good to know that you like the tutorial but why you are saying its copy paste content ? though you can find content on thousands of sites but every post should be unique my friend.

Gaurav Dubey said...

@Javin I believe we need to add some important things here. I am putting them if information is ok then please add them in your article.

mysqldump will backup by default all the triggers but NOT the stored procedures/functions.
There are 2 mysqldump parameters that control this behavior:

–routines - FALSE by default
–triggers - TRUE by default
So if you want to take backup of whole database +procedures/ functions you can do it by below command

mysqldump -u username -p database_name --routines > output_db_file_name.sql

Javin Paul said...

@Gaurav, Thanks for sharing these important information about mysqldump utility, I will surely add them.

Post a Comment