/pmdump

A library can dump mysql databases into a SQL file with limited permissions account and none-tables-locking.

Primary LanguagePHP

Introduction:

A library can be used to dump mysql database into a SQL file just like mysqldump does, but it never lock any tables. If the table is changed when dumping, the final data dumped with the library will be not as same as the origin database.

BTW: The mysql account only need the "SELECT" permission.

Usage: 

<?php
require '/path/to/pmdump/lib/PMDump.php';

$pdo = new PDO('mysql:dbname=test;host=localhost', 'mysqluser', 'pa$$W0rd');
$pmdump = new PMDump($pdo, array(

    # LIMIT number of rows per query
    'limit_per_select' => 500, 

    // add "DROP TABLE ..."
    'add_drop_table' => true,

    // add tables need ignored
    'excluded_tables' => array(),
), 'UTF8);
$pmdump->dump('database_name_here', '/path/to/file.sql');
?>

Importing the SQL file into a mysql server:
$ mysql -u root -p dbname < /path/to/file.sql