Skip to content

Instantly share code, notes, and snippets.

@micc83
Created June 5, 2017 13:17
Show Gist options
  • Save micc83/fe6b5609b3a280e5516e2a3e9f633675 to your computer and use it in GitHub Desktop.
Save micc83/fe6b5609b3a280e5516e2a3e9f633675 to your computer and use it in GitHub Desktop.
Simple PHP script to dump a MySql database
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$database = 'db';
$user = 'user';
$pass = 'pass';
$host = 'localhost';
$dir = dirname(__FILE__) . '/dump.sql';
echo "<h3>Backing up database to `<code>{$dir}</code>`</h3>";
exec("mysqldump --user={$user} --password={$pass} --host={$host} {$database} --result-file={$dir} 2>&1", $output);
var_dump($output);
@pthavarasa
Copy link

@smitione
Copy link

smitione commented Oct 20, 2022

Hi, first at all, GREAT SCRIPT...! now i have to questions: 1)- how can i zip the dump? 2)- How can i for the download after finish? Suggestions or ideas? Best regards.

@micc83
Copy link
Author

micc83 commented Oct 21, 2022

Hi @smitione look here, you should find everything you're looking for: https://stackoverflow.com/a/4369173

@hanita0o0
Copy link

thanksssss alot i had very struggle for this command and now i find it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment