Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump all tables as individual files #223

Open
IrishTLR opened this issue Mar 23, 2021 · 4 comments
Open

dump all tables as individual files #223

IrishTLR opened this issue Mar 23, 2021 · 4 comments

Comments

@IrishTLR
Copy link

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
Copy link
Owner

ifsnop commented Mar 23, 2021 via email

@IrishTLR
Copy link
Author

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
Copy link
Contributor

phpony commented Mar 23, 2021

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants