IT Community - Software Programming, Web Development and Technical Support

mysql database dump tips and tricks

This is a discussion on mysql database dump tips and tricks within the Database Support forums, part of the Web Development category; Hi, Here i share with you some tips and tricks about mysql dump options. Generally we use the command "...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 09-22-2007, 12:20 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default mysql database dump tips and tricks

Hi,
Here i share with you some tips and tricks about mysql dump options.

Generally we use the command "mysqldump" to take the mysql database dump.


Syntax:
mysqldump [options] db_name [tables] > File path
Example:
mysqldump -u root testdb > /home/backup/db_dump.sql
This command is used to take the backup of database "testdb" tables and its data's into specified file path.


i will share with you the more tips about mysqldump in the up coming posts.... till good bye...
Regards,
S.Ashokkumar
.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-23-2007, 10:03 PM
prasath prasath is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: Chennai
Posts: 173
prasath is on a distinguished road
Default Re: mysql database dump tips and tricks

hi,
explain how we take dump as particular table...


We need more information from u....


Thanks,
Prasath.K
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-23-2007, 11:38 PM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

Hi,

To take a backup of particular table, we can use the following command...


Syntax:
mysqldump <options> <databasename> <tablename> > <file path>


Example:
mysqldump -u root --extended-insert testdb testtable > /home/backup/dump_table.sql


Options:

--extended-insert => Use multiple-row INSERT syntax that include several VALUES lists. This results in a smaller dump file and speeds up inserts when the file is reloaded.



Regards,
S.Ashokkumar
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-25-2007, 05:43 AM
prasath prasath is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: Chennai
Posts: 173
prasath is on a distinguished road
Red face Re: mysql database dump tips and tricks

Hi,
It is very useful one...........................


Thanks,
Prasath.K
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-25-2007, 06:09 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

Hi,

For generally, when taking the mysql database backup by using general options, the store procedure and functions are wont include in the backup script... so we use the some special options for take the backup to stored procedure and functions.



Example :
mysqldump -u root --routines testdb > /home/backup/dump_data.sql
Options:

--routines => Dump stored routines (functions and procedures) from the dumped databases

Regards,
S.Ashokkumar

Last edited by write2ashokkumar : 09-25-2007 at 06:24 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 09-25-2007, 10:38 PM
prasath prasath is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: Chennai
Posts: 173
prasath is on a distinguished road
Smile Re: mysql database dump tips and tricks

Hi,
How we take back up routines & also tables simultanously


Thanks,
Prasath.K
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-25-2007, 11:20 PM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

Hi,

Table are default while we take the dump.... for the routines we include the additional options... see the above post.... this command is used to take the backup of tables and routines...



Regards,
S.Ashokkumar
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-26-2007, 06:07 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

Hi,

To take the backup of all the database, we can use the following command,


Example:
mysqldump -u root --routines --extended-insert --all-databases > /home/backup/mysql_dump.sql


Regards,
S.Ashokkumar
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 09-26-2007, 06:37 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: mysql database dump tips and tricks

Hi techies,

I am using mysqldump utility for taking mysql backup, have written a shell script and scheduled that script to run around 12:00 am for backup process.

It's taking backup and keep the backup (*.sql) file in the same server path itself. I want to store the backed contents in some other (remote) server location so that i can able to restore it if the running mysql server crashed completely.

Can u please help me out ?
__________________
Keep smiling...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-27-2007, 11:14 PM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

Hi,


We cant able to store the backup file in the remote server while taking the backup.... Only the way is, first take the backup in the db server(same server), then move the backup file to remote server.



Regards,
S.Ashokkumar.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 09-28-2007, 03:56 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: mysql database dump tips and tricks

Hi Ashok,

thanks, this could be possible if the destination file server also running with MySQL. So that we can deploy the shell script in the destination server and connect the main db server for taking backup.
__________________
Keep smiling...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 09-28-2007, 04:39 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: mysql database dump tips and tricks

Use WHERE condition with mysqldump

Here is another tip that we can use WHERE condition with mysqldump.

mysqldump --where='where_condition', -w 'where_condition'

this option dump only the rows that satisfied the where condition.

Eg.

Quote:
mysql> use test;
Database changed
mysql> select * from orders;
+----------+---------------------+-------------+
| order_id | orderdate | orderamount |
+----------+---------------------+-------------+
| 1 | 2007-09-28 15:30:04 | 1500 |
| 2 | 2007-09-28 15:20:18 | 21500 |
| 3 | 2007-09-28 15:31:12 | 21500 |
| 4 | 2007-09-28 15:21:23 | 15700 |
| 5 | 2006-11-28 15:48:45 | 13265 |
| 6 | 2006-06-28 15:48:56 | 10265 |
| 7 | 2005-08-28 15:49:09 | 5265 |
+----------+---------------------+-------------+

root:~> mysqldump -u root -p -w "orderamount>20000" test orders

The dump sql file will be like this

-- MySQL dump 10.10

-- Dumping data for table `orders`
--
-- WHERE: orderamount>20000

INSERT INTO `orders` VALUES (2,'2007-09-28 15:20:18',21500),(3,'2007-09-28 15:31:12',21500);

--
__________________
Keep smiling...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 10-03-2007, 04:45 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

hi,

Here is one more tips..

To add the drop database statement in backup script, we need to included the additional options in the command.


Example:
mysqldump -u root --add-drop-database test_db > /home/backup/dump_sample.sql


Option:
--add-drop-database => Add a DROP DATABASE statement before each CREATE DATABASE statement.

Regards,
S.Ashokkumar.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 10-04-2007, 07:35 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

hi,

To add the drop table statement while creating the backup of database, we can use the option "--add-drop-table " in the mysqldump command.


Example:

mysqldump -u root --add-drop-table test_db > /home/backup/dump_sample.sql



Option:
--add-drop-table => Add a DROP TABLE statement before each CREATE TABLE statement.

Regards,
S.Ashokkumar.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 10-05-2007, 12:43 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

hi,

To add the lock table statement while taking the backup in the script, we can use the option "--add-locks".

Example:
mysqldump -u root --add-locks test_db > /home/backup/dump_sample.sql



Option :


--add-locks => Surround each table dump with LOCK TABLES and UNLOCK TABLES statements. This results in faster inserts when the dump file is reloaded.



Regards,
S.Ashokkumar.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 10-08-2007, 08:30 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

hi,

For continue the operation even if the SQL error occurs during the table dump, we need to include the additional option "--force" in the mysqldump command.



Example:
mysqldump -u root --force test_db > /home/backup/dump_sample.sql



Option:

--force => Continue even if an SQL error occurs during a table dump.
Regards,
S.Ashokkumar
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 10-09-2007, 08:12 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: mysql database dump tips and tricks

hi,

To create the XML formated dump, we can use the option "--xml" in the mysqldump command.


Example:
mysqldump -u root -xml test_db > /home/backup/dump_sample.sql



Option:

--xml => Write dump output as well-formed XML.


Regards,
S.Ashokkumar.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 10-31-2007, 08:40 AM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: mysql database dump tips and tricks

Hi Techies,

Can someone explain about how to avoid excessive memory usage while exporting records from large databases ?
__________________
Keep smiling...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 11-08-2007, 10:07 PM
Gopisoft Gopisoft is offline
D-Web Sr.Programmer
 
Join Date: Feb 2007
Posts: 117
Gopisoft is on a distinguished road
Default Re: mysql database dump tips and tricks

Yes we've face this same problem
Error Message is "mysqldump: Error 5: Out of Memory (Needed 4236040 bytes) when dumping table 'table_name' at row_number"

Need to increase the RAM memory or MySQL buffer size.

Thanks,
R.Gopi
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 11-09-2007, 11:22 PM
priyan priyan is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 133
priyan is on a distinguished road
Default Re: mysql database dump tips and tricks

Yes, increasing RAM / Buffer size could solve this problem.

We can also use

Quote:
--skip-quick
Generally mysqldump uses --quick option by default. --quick option will retrieve data from table one by one rather than loading the entire data from large table and buffer it in memory before dumping it. This could cause excessive memory usage. You can use --skip-quick option if you want skip this option.
__________________
Keep smiling...

Last edited by priyan : 12-18-2007 at 07:13 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/database-support/3927-mysql-database-dump-tips-tricks.html
Posted By For Type Date
DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 09-24-2007 12:55 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Toad for MySQL Tips & Tricks Sabari Database Support 56 12-20-2007 01:46 AM
Upload Files to MySQL using PHP Tips & Tricks Sabari PHP Programming 3 12-18-2007 06:32 AM
Importing mysql dump file to my Local Server Murali Database Support 1 12-12-2007 07:10 AM
How to import MySQL Dump files? kingmaker Database Support 2 07-24-2007 04:47 AM
mysql dump JSureshkumar PHP Programming 3 03-14-2007 04:55 AM


All times are GMT -7. The time now is 06:35 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0