ifsnop / mysqldump-php

PHP version of mysqldump cli that comes with MySQL
https://github.com/ifsnop/mysqldump-php
GNU General Public License v3.0
1.25k stars 300 forks source link

dump all tables as individual files #223

Open IrishTLR opened 3 years ago

IrishTLR commented 3 years ago

Hi, only came across this project today and am already loving and using it. Just wondering, is there an option to dump all tables in individual files rather than the entire database as one file? Our databases are multi GB and our problem is restoring. We rather restore tables rather than the entire database in one go.

ifsnop commented 3 years ago

Hi, only came across this project today and am already loving and using it. Just wondering, is there an option to dump all tables in individual files rather than the entire database as one file? Our databases are multi GB and our problem is restoring. We rather restore tables rather than the entire database in one go.l

Thanks for your kind words. Currently is not possible to use several files. I can only think about hacks, but none of them would be really useful. Best thing is to call mysqldump-php one for each table, but if you have another option in mind, just tell.

Regards,

IrishTLR commented 3 years ago

Thanks for the update. I'll dig around over the next few days/weeks and see if I can come up with something and push it back.

phpony commented 3 years ago

That shouldn't be a big deal because you have include-tables option. Just run in for each table individually:

$user = 'user';
$pass = 'pass';
$dbname = 'test';
$dbhost = 'localhost';

$dbh = new PDO("mysql:host={$dbhost};dbname={$dbname}", $user, $pass);
foreach($dbh->query("SHOW TABLES IN `{$dbname}`") as $row) {
    $table = current($row);
    $dump = new IMysqldump\Mysqldump("mysql:host={$dbhost};dbname={$dbname}", $user, $pass, array("include-tables" => array($table)));
    $dump->start("dumps/{$table}.sql");
}
IrishTLR commented 3 years ago

Nice one. Thanks phpony. The simplest solutions are often the best. Works perfectly.