Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: mysqldump

  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts

    Question mysqldump

    Hi

    Does anyone know what is the simplest way to backup a database using the mysqldump function in php?


    I have googled a lot and the codes i have found are very hard to understand and most of them does not work.



    Thanx in advance for your help.

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    PHP Code:
    exec('/path/to/mysqldump --host=hostname --user=username --password=password dbname >output.sql'); 

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    There is no mysqldump function in php. Do you mean the mysqldump executable supplied with MySQL?
    If so you can run mysqldump from php using:
    Code:
    $host="localhost";
    $username="root";
    $password="myPassword";
    $database="myDbName";
    $path="C:\\";
    $filename="myDbBackup.sql";
    $command ="mysqldump --host=$host --user=$username --password=$password $database > $path/$filename"; 
    exec($command);
    Subsitute your values as applicable.

  • #4
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    HI

    Thanx for your reply. Now can u tell me how would I restore my data to the database?

  • #5
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts

  • #6
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Code:
    $command = "mysql -u USER -p DBNAME < myDbBackup.sql";
    exec($command);
    Should be something like this if I remember correctly.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •