Webmaster Help AwProfits
|
Welcome, Guest. Please login or register.
Did you miss your activation email?
Jan 06, 2009, 02:04:44 AM

Login with username, password and session length

I have never accepted what many people have kindly said — namely that I inspired the nation. Their will was resolute and remorseless, and as it proved, unconquerable. It fell to me to express it.


- Winston Churchill

Welcome Guest - Register or Login Now to remove these advertisments


Registration is completely free and only takes a few minutes to signup !

|-   Entrepreneur Forum > Webmasters - Discuss Making Money Online > Website Design and Maintenance > Database
+   Need an example of how to use mysqldump
0 Members and 1 Guest are viewing this topic.
Pages: [1] Reply to Thread
Author Topic: Need an example of how to use mysqldump  (Read 369 times)
OnlineGalaxian
Senior Member
Galaxian is on a distinguished road
Joined: Oct 2007
Posts: 238


Avatar of Galaxian

The internet is my playground.

View Galaxian\s Profile
Gender: MaleAries United States
notepad Feb 08, 2008, 11:55:30 AM #1
Can anyone please write out a complete php working example of how to do a mysqldump on an entire database?

Please, I would like to automate my backupprocess with a PHP script.

Latest Blog Post : The Advantages of Water-Powered Car Technology

Got an eye for The Best Cars like a sizzling Ferrari sports car or the luxury of BMW?
OfflineMrMango
Junior Member
MrMango is on a distinguished road
Joined: Jan 2007
Posts: 57


Avatar of MrMango

View MrMango\s Profile
United Kingdom
notepad Feb 08, 2008, 01:00:46 PM #2
 The most common use of mysqldump is probably for making a backup of an
       entire database:

       shell> mysqldump --opt db_name > backup-file.sql

       You can read the dump file back into the server like this:

       shell> mysql db_name < backup-file.sql

       Or like this:

       shell> mysql -e "source /path-to-backup/backup-file.sql" db_name

OfflineAceCoder
Junior Member
AceCoder is on a distinguished road
Joined: Oct 2007
Posts: 64



View AceCoder\s ProfileWWW
Germany
notepad Feb 10, 2008, 07:58:15 PM #3
That's fine if you have access to the command line but how can you do these in PHP?

Latest Blog Post : PHP - Pass by Reference or Pass by Value

Online~Dave~
Administrator
~Dave~ is a jewel in the rough~Dave~ is a jewel in the rough~Dave~ is a jewel in the rough~Dave~ is a jewel in the rough
Joined: Jan 2006
Posts: 6186


Avatar of code4gol

Building a Foundation

View ~Dave~\s ProfileWWW
Gender: MaleGemini United States
notepad Feb 10, 2008, 10:30:38 PM #4
You could do something like this in PHP using the PHP system() command

Code:
$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
system($command);

Otherwise you could use a SQL statement to dump the data

Code:
$backupFile = '/path/to/backup/mytable.sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM myTable";
$result = mysql_query($query);

You could read that back in like this...

Code:
$backupFile = 'mytable.sql';
$query      = "LOAD DATA INFILE '$backupFile' INTO TABLE myTable";
$result = mysql_query($query);

If you have any question, ask away...

Latest Blog Post : Social Media Optimization for Social Media Marketing

Pages: [1] Reply to Thread


Code4Gold Affiliate Entrepreneur Moneymaker Forum © 2006-2008 Resdaz Media LLC - All Rights Reserved

Forum Software Powered by SMF - © 2001-2008, Lewis Media. All Rights Reserved.