www.webdeveloper.com
Results 1 to 7 of 7

Thread: PHP/MySQL Dump to File

  1. #1
    Join Date
    Jun 2004
    Location
    California, USA
    Posts
    264

    PHP/MySQL Dump to File

    Hello,

    So I want to create a php script that will use the MySQL dump feature to dump my database (and specified tables) to a file that I will create on the fly with php. Is this possible? I did some research but could not find anything.

    Any help is appreciated, thanks.

    PS I know I can just use PHPMyAdmin to dump the contents of my database, but I am trying to create this script, so it will automatically make a file on the server and save the dump contents.

    Thanks

  2. #2
    Join Date
    Jun 2006
    Posts
    38
    cron this

    $filename= "backupname-$datestamp.sql.gz"; // The name path of the dump file

    $command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
    $result = passthru($command);

  3. #3
    Join Date
    Jun 2004
    Location
    California, USA
    Posts
    264
    would doing it this way require me to have the file already created on the server? I wanted to create the file automatically.

    Also in the MySQLDump command, how do I specify which tables to dump. I woulld like to ignore some tables.

  4. #4
    Join Date
    Jun 2006
    Posts
    38
    no you will not have to have the file already on the server. it will automatically create it in the directory.

    http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html

    You could then ftp that file or email it if it was small or whatever you want to do with it...

  5. #5
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Here's the best source for mysqldump

    http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html

  6. #6
    Join Date
    Jun 2004
    Location
    California, USA
    Posts
    264
    so i try this:

    PHP Code:
    $command "mysqldump dbname orders > file.sql"
    and i see that the file is created, but the file is empty. is there an error log I can look up?

    Am I doing this wrong? I tried it with the commands for user and password but that didnt work either.

  7. #7
    Join Date
    Jun 2004
    Location
    California, USA
    Posts
    264
    any reason why I the file is created but empty? it looks to me like I am not getting connected to the database, but i do not get any error messages. is there an mysql_error log somewhere?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles