Giter Site home page Giter Site logo

ifsnop / mysqldump-php Goto Github PK

View Code? Open in Web Editor NEW
1.2K 55.0 300.0 419 KB

PHP version of mysqldump cli that comes with MySQL

Home Page: https://github.com/ifsnop/mysqldump-php

License: GNU General Public License v3.0

PHP 85.40% Shell 14.60%
mysql mysqldump pdo php7 php5 database php sql hhvm mariadb

mysqldump-php's Introduction

MySQLDump - PHP

Requirements | Installing | Getting started | API | Settings | PDO Settings | TODO | License | Credits

Build Status Total Downloads Monthly Downloads Daily Downloads Scrutinizer Quality Score Latest Stable Version

This is a php version of mysqldump cli that comes with MySQL, without dependencies, output compression and sane defaults.

Out of the box, MySQLDump-PHP supports backing up table structures, the data itself, views, triggers and events.

MySQLDump-PHP is the only library that supports:

  • output binary blobs as hex.
  • resolves view dependencies (using Stand-In tables).
  • output compared against original mysqldump. Linked to travis-ci testing system (testing from php 5.3 to 7.3 & hhvm)
  • dumps stored routines (functions and procedures).
  • dumps events.
  • does extended-insert and/or complete-insert.
  • supports virtual columns from MySQL 5.7.
  • does insert-ignore, like a REPLACE but ignoring errors if a duplicate key exists.
  • modifying data from database on-the-fly when dumping, using hooks.
  • can save directly to google cloud storage over a compressed stream wrapper (GZIPSTREAM).
  • can restore a dump from a file, when no mysql executable is available.

Important

From version 2.0, connections to database are made using the standard DSN, documented in PDO connection string.

Requirements

  • PHP 5.3.0 or newer
  • MySQL 4.1.0 or newer
  • PDO

Installing

Using Composer:

$ composer require ifsnop/mysqldump-php

Using Curl to always download and decompress the latest release:

$ curl --silent --location https://api.github.com/repos/ifsnop/mysqldump-php/releases | grep -i tarball_url | head -n 1 | cut -d '"' -f 4 | xargs curl --location --silent | tar xvz

Getting started

With Autoloader/Composer:

<?php

use Ifsnop\Mysqldump as IMysqldump;

try {
    $dump = new IMysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password');
    $dump->start('storage/work/dump.sql');
} catch (\Exception $e) {
    echo 'mysqldump-php error: ' . $e->getMessage();
}

Plain old PHP:

<?php

    include_once(dirname(__FILE__) . '/mysqldump-php-2.0.0/src/Ifsnop/Mysqldump/Mysqldump.php');
    $dump = new Ifsnop\Mysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password');
    $dump->start('storage/work/dump.sql');

Refer to the wiki for some examples and a comparision between mysqldump and mysqldump-php dumps.

Changing values when exporting

You can register a callable that will be used to transform values during the export. An example use-case for this is removing sensitive data from database dumps:

$dumper = new IMysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password');

$dumper->setTransformTableRowHook(function ($tableName, array $row) {
    if ($tableName === 'customers') {
        $row['social_security_number'] = (string) rand(1000000, 9999999);
    }

    return $row;
});

$dumper->start('storage/work/dump.sql');

Getting information about the dump

You can register a callable that will be used to report on the progress of the dump

$dumper->setInfoHook(function($object, $info) {
    if ($object === 'table') {
        echo $info['name'], $info['rowCount'];
    });

Table specific export conditions

You can register table specific 'where' clauses to limit data on a per table basis. These override the default where dump setting:

$dumper = new IMysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password');

$dumper->setTableWheres(array(
    'users' => 'date_registered > NOW() - INTERVAL 3 MONTH AND deleted=0',
    'logs' => 'date_logged > NOW() - INTERVAL 1 DAY',
    'posts' => 'isLive=1'
));

Table specific export limits

You can register table specific 'limits' to limit the returned rows on a per table basis:

$dumper = new IMysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password');

$dumper->setTableLimits(array(
    'users' => 300,
    'logs' => 50,
    'posts' => 10
));

Constructor and default parameters

/**
 * Constructor of Mysqldump. Note that in the case of an SQLite database
 * connection, the filename must be in the $db parameter.
 *
 * @param string $dsn        PDO DSN connection string
 * @param string $user       SQL account username
 * @param string $pass       SQL account password
 * @param array  $dumpSettings SQL database settings
 * @param array  $pdoSettings  PDO configured attributes
 */
public function __construct(
    $dsn = '',
    $user = '',
    $pass = '',
    $dumpSettings = array(),
    $pdoSettings = array()
)

$dumpSettingsDefault = array(
    'include-tables' => array(),
    'exclude-tables' => array(),
    'compress' => Mysqldump::NONE,
    'init_commands' => array(),
    'no-data' => array(),
    'if-not-exists' => false,
    'reset-auto-increment' => false,
    'add-drop-database' => false,
    'add-drop-table' => false,
    'add-drop-trigger' => true,
    'add-locks' => true,
    'complete-insert' => false,
    'databases' => false,
    'default-character-set' => Mysqldump::UTF8,
    'disable-keys' => true,
    'extended-insert' => true,
    'events' => false,
    'hex-blob' => true, /* faster than escaped content */
    'insert-ignore' => false,
    'net_buffer_length' => self::MAXLINESIZE,
    'no-autocommit' => true,
    'no-create-db' => false,
    'no-create-info' => false,
    'lock-tables' => true,
    'routines' => false,
    'single-transaction' => true,
    'skip-triggers' => false,
    'skip-tz-utc' => false,
    'skip-comments' => false,
    'skip-dump-date' => false,
    'skip-definer' => false,
    'where' => '',
    /* deprecated */
    'disable-foreign-keys-check' => true
);

$pdoSettingsDefaults = array(
    PDO::ATTR_PERSISTENT => true,
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
);

// missing settings in constructor will be replaced by default options
$this->_pdoSettings = self::array_replace_recursive($pdoSettingsDefault, $pdoSettings);
$this->_dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);

Dump Settings

The following options are now enabled by default, and there is no way to disable them since they should always be used.

PDO Settings

Errors

To dump a database, you need the following privileges :

  • SELECT
    • In order to dump table structures and data.
  • SHOW VIEW
    • If any databases has views, else you will get an error.
  • TRIGGER
    • If any table has one or more triggers.
  • LOCK TABLES
    • If "lock tables" option was enabled.

Use SHOW GRANTS FOR user@host; to know what privileges user has. See the following link for more information:

Which are the minimum privileges required to get a backup of a MySQL database schema?

Tests

Current code for testing is an ugly hack. Probably there are much better ways of doing them using PHPUnit, so PR's are welcomed. The testing script creates and populates a database using all possible datatypes. Then it exports it using both mysqldump-php and mysqldump, and compares the output. Only if it is identical tests are OK. After this commit, some test are performed using phpunit.

Some tests are skipped if mysql server doesn't support them.

A couple of tests are only comparing between original sql code and mysqldump-php generated sql, because some options are not available in mysqldump.

Bugs (from mysqldump, not from mysqldump-php)

After this bug report, a new one has been introduced. _binary is appended also when hex-blob option is used, if the value is empty.

Backporting

mysqldump-php is not backwards compatible with php 5.2 because we it uses namespaces. However, it could be trivially fixed if needed.

Todo

Write more tests, test with mariadb also.

Contributing

Format all code to PHP-FIG standards. https://www.php-fig.org/

License

This project is open-sourced software licensed under the GPL license

Credits

After more than 8 years, there is barely anything left from the original source code, but:

Originally based on James Elliott's script from 2009. https://code.google.com/archive/p/db-mysqldump/

Adapted and extended by Michael J. Calkins. https://github.com/clouddueling

Currently maintained, developed and improved by Diego Torres. https://github.com/ifsnop

mysqldump-php's People

Contributors

andreas-glaser avatar antoine-rehm avatar barrymieny avatar bomoko avatar bradjones1 avatar bwmarkle avatar christiandavilakoobin avatar clouddueling avatar cupoftea696 avatar garas avatar guvra avatar gwarnants avatar hisorange avatar ifsnop avatar judgej avatar lubosdz avatar lukeb avatar maikeldaloo avatar nerijusnoreika avatar ntomka avatar paulgav avatar piotrantosik avatar rvanlaak avatar savagecore avatar scrutinizer-auto-fixer avatar sjorso avatar slamdunk avatar smalos avatar stevenbrookes avatar tomsommer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mysqldump-php's Issues

Class 'Ifsnop\Mysqldump\Mysqldump' not found

I just upgraded from Clouddueling/Mysqldump to dev-master using Composer.

I followed the example from the README and it runs great on my PHP 5.5 instances.

I have a few older PHP 5.3.15 instances that show the class not found error. I still have to support those for a short time.

Any thoughts or workarounds?

Improve coding convention

  • The Mysqldump.php should consist of only 1 class which has the name of Mysqldump.
    Other classes such as CompressMethod, CompressManagerFactory, etc should be placed in separated files which have the same name as class.
  • Use camelCase for naming class methods. For example:

TypeAdapterFactory::show_create_table should be TypeAdapterFactory::showCreateTable

Cannot Install

Hello

I just ran php artisan bundle:install mysqldump-php as seen from the Laravel website.

However, it comes back with an error:

Fetching [mysqldump-php]...
Warning: file_get_contents(http://nodeload.github.com/clouddueling/mysqldump-php/zipball/master): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
 in [PATH]/laravel/cli/tasks/bundle/providers/provider.php on line 69

Notice: Undefined variable: bundle in [PATH]/laravel/cli/tasks/bundle/providers/provider.php on line 76
Error downloading bundle [].

Foreign key constraints

Doesn't order tables or data with respect for foreign keys; the result as-is is cannot be re-imported without modification to the generated sql because of constraints referencing columns in tables yet to be created. There are options that can be added to the script to disable foreign key checks while inserting the data but there is no way around properly ordering the table creation or removing the constraints in the table definitions and adding them after all of the tables have been created.

Table was not locked with LOCK TABLES

When trying to restore a dump I get the error message:

Error
SQL query: DocumentationEdit Edit

SELECT comment
FROM phpmyadmin.pma_column_info
WHERE db_name = 'test'
AND table_name = ''
AND column_name = '(db_comment)'

MySQL said: Documentation
#1100 - Table 'pma_column_info' was not locked with LOCK TABLES

I tried both "lock-tables" true and the default (false, according to the documentation)

Add port number

Add port number to the Mysqldump constructor.
Currently it is using the default port number.

Export NULL value as empty string

See export below. Values that show (by PHPMyAdmin) as NULL are exported as empty string ''

-- Table structure for table table_name

CREATE TABLE table_name (
item_id int(11) NOT NULL auto_increment,
category_id int(11) default NULL,
title varchar(255) default NULL,
alias varchar(255) default NULL,
position int(11) default NULL,
active int(11) default NULL,
create_time datetime default NULL,
modified_time datetime default NULL,
start_time date default NULL,
end_time date default NULL,
key1 varchar(50) default NULL,
key2 varchar(50) default NULL,
key3 varchar(50) default NULL,
PRIMARY KEY (item_id)
) ENGINE=MyISAM AUTO_INCREMENT=29 DEFAULT CHARSET=utf8;

-- Dumping data for table table_name

INSERT INTO table_name VALUES('1', '', 'xxx', 'xxx-xxxl', '1', '1', '2013-04-14 21:02:31', '2013-04-14 21:02:31', '', '', '', '', '');

streams

Hi

i've been experimenting with your library for a bit. I found that while you can write to 'php://sndout' stream you by giving that string as argument it is not possible to provide your own resource.

$handle = fopen('php://temp', 'w+');

$dumper->start($handle);

/* $filesystem is a virtual filesystem, from https://github.com/thephpleague/flysystem */
$filesystem->writeStream($path, $handle);
fclose($handle);

I'v been able to do this for the uncompressed version by modifying the compression class a bit. (basically test if resource then use it and don't close it). However the compressed version need to do gzopen or bzopen so that won't be that easy.

Unfortunately I am not very good at resource handling. I just don't see how to do this - though i think it must be possible with custom stream wrappers. I'm hoping you see a feature like this would be useful and see a way to implement this into a future version...

Thanks!

Unstyled code

all code needs to be converted to PHP-FIG not this rambling of different styles.

mysqldump-php error: Output file is not writable

I try to use mysqldump-php with composer. But i always have this error:

PHP Warning:  fopen(/home/www/database/): failed to open stream: Is a directory in /home/www/m10a3/server/vendor/ifsnop/mysqldump-php/src/Ifsnop/Mysqldump/Mysqldump.php on line 824
mysqldump-php error: Output file is not writable

Class PDO not found after using namespaces

Am I the only one with this problem when using mysqldump-php after the last update for using namespaces?

Fatal error: Class 'Clouddueling\Mysqldump\PDO' not found in libs/external/mysqldump-php/src/Clouddueling/Mysqldump/mysqldump.php on line 38

Setting "include-tables" does not exclude all non-mentioned tables

The white-listing setting "include-tables" does not block all other (not listed) tables.

Steps to reproduce:

Create a database containing tables t1, t2 and t3.
Export it with _settings["include-tables"] set to array("t1", "t2").

Expected result:

Tables t1 and t2 exported.

Actual result:

Tables t1, t2 and t3 exported
(Actually, this depends also on the order in which TypeAdapterFactory->showTables() reports the existing tables)

uppercase dbnames

Hi
Since the PDO version the dbnames with uppercase characters does not dump any tables anymore.
I think line 220 needs to be modified from

$this->dsnArray[$kvpArr[0]] = strtolower($kvpArr[1]);

to

$this->dsnArray[strtolower($kvpArr[0])] = ($kvpArr[1]);

Add option/documentation to disable query buffering

I constantly got memory exhausted errors at $resultSet = $this->_dbHandler->query($stmt);

Apparently, this was caused by mysqlnd buffering queries: Stack Overflow: Unexpectedly hitting PHP memory limit with a single PDO query?
After adding PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false to $pdoOptions the script worked.
As this might be a common problem, this solution should be added to the readme, and even perhaps a new parameter could be added to the $settings array. Alternatively one could work out the impact of making this the default option (performance loss if there's enough memory).

This is the best standalone PHP mysqldump script I have found so far, thanks for all the work! :)

Testing!

We need some testing, maybe via

https://travis-ci.org/

New release

Hi,

I just spent a while trying to figure out an error related to privileges, then I noticed it has been fixed :)
Are you planning a new release soon?

thanks

Add executable comments / set assignments to improve compatibility

In order to improve cross-version compatibility, it would be nice to implement code containing comments. This also will make the exports more usable, since executing the backup will result in less errors. Example codes are:

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

This can also be used in order to disable keys on import. It could be an extension of the --add-locks parameter.

http://dev.mysql.com/doc/refman/5.6/en/set-statement.html

Connection options

I can't seem to find a way to set this flag:

--protocol={TCP|SOCKET|PIPE|MEMORY}

The connection protocol to use for connecting to the server. It is useful when the other connection parameters normally would cause a protocol to be used other than the one you want. For details on the permissible values, see Section 4.2.2, “Connecting to the MySQL Server”.

What if I am connecting via a socket?

For example:
https://help.1and1.com/hosting-c37630/databases-c85147/mysql-database-c37730/connect-to-a-mysql5-database-on-a-1and1-managed-server-a752513.html\

Or will the library correctly parse the host value?

Licensing when used inside a phar binary

Hi Diego

I'm currently writing a small console application which dumps a database and then uploads it to Amazon S3. Consequently this tool is licensed under GPL, as the mysqldump-php project requires. Now what I'm a little unclear about is if I'm allowed to offer a phar binary package. Basically the whole tool inside one binary file. If not, every user would have to compile it himself, which is not really user friendly (but of course I will respect the license).

Thanks for both your great project and feedback!
Cheers,
Marcel

Taking ownership

Hi there,

If you don't mind, and since I have also write access to the repo, I would like to keep updating mysqldump-php (merging PR and adding coding sometimes). I also use mysqldump-php in some of my virtual machines.

Is it ok if you keep ownership and I continue with write access?

OTOH, if you don't want to continue owning this repo, I could take care of it.

Regards,

Other database as dump target

One of the nice features of linux mysqldump is that another database can be the target. In that way it is quite easy to migrate databases.

I think dumping to an external target database also could be a feature of this mysqldump script, since most of the work has already been done for that.

Since most servers support compressed connections, it even should be possible to start to make use of the MYSQL_CLIENT_COMPRESS client flags.

http://www.php.net/manual/en/mysql.constants.php#mysql.client-flags

Adjust options names in accordance with original ones

I think it would be a right way to throw away all these custom var names ($droptableifexists, $nodata and so on) and replace them with commonly used standart names (and add some new features):

add-drop-database
add-drop-table
add-locks
all-databases
complete-insert
delayed-insert
disable-keys
flush-privileges
insert-ignore
lock-all-tables
lock-tables
no-autocommit
no-data
quote-names
replace

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

Memory/connection problems

I'm investigating some sort of bug in the behavior of mysqldump, after using it in a VM, mapped on a routed api, after 2 or 3 days of usage, suddenly everything stop working, there is a weird high memory usage on machine and after mysqldump->start it don't write on disk at all,
No error messages. I don't know actually why this is happening, probably it full some buffer,socket or memory somewhere.
This is the "ps aux --sort -rss" result
mysql 32344 0.0 24.0 1152460 460576 pts/2 Sl 10:39 0:02 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

Even restarting mysql it won't help, 2 minutes of using it and it's back on this resources

events

Please export EVENTS

mysql> CREATE EVENT e_totals
-> ON SCHEDULE AT '2006-02-10 23:59:00'
-> DO INSERT INTO test.totals VALUES (NOW());

Question about license

I've found this line in code

@license  http://www.gnu.org/copyleft/gpl.html GNU General Public License

But in README license is MIT
Who's right?

CompressManagerFactory::open should not append file extension if compression enabled

Currently, CompressManagerFactory::open() append a file extension to the written dump depending on the enabled compression method (".gz" if GZIP, ".bz2" if BZIP2). I think users should decide the real output filename they want. This will solve many problems to deduct the output filename if internal classes didn't change the filename anymore.

$settings = array(
    'compress' => Mysqldump::GZIP
);
$dump = new Mysqldump($db, $username, $password, $host, $type, $settings);

// currently :
$dump->start('dump.sql'); // write dump.sql.gz

// should become :
$dump->start('dump.sql.gz'); // write dump.sql.gz

Text file Encoding

Hi, earlier I told u about the utf8mb4 character set problem and you solved. This time, when I run the codes using this

$dump = new Mysqldump( $dbname, $dbuser, $dbpass,$dbhost."",'mysql',array('single-transaction' => false,'compress' => 'BZIP2','default-character-set' => Mysqldump::UTF8MB4));
$dump->start('ydk/'.time().'.sql');

And the file saved fine.

But somethings not right.

If I run the codes and db>table>field has '🐈', file saved as ANSI encoding and the cat looked like ğŸ�ˆ
If field has not the '🐈' file saved as UTF8 without BOM

Thank you for solving the problems

Date still in output independant of skip-dump-date

Hi,
Just a small correction.
in getDumpFileHeader there is a

 $header .= "-- Date: " . date('r') . PHP_EOL . PHP_EOL;

that is not controled by skip-dump-date
My suggestion:

            if (!$this->dumpSettings['skip-dump-date']) {
                    $header .= "-- Date: " . date('r') . PHP_EOL . PHP_EOL;
            }

include-tables bug

method getDatabaseStructure():
-consider non empty include-tables.
-foreach removes all the records from $this->dumpSettings'include-tables'
$this->dumpSettings['include-tables'] is now empty resulting dump all the views.

also the set of triigers should respect the set of exported tables - create all the triggers for exported tables and no one for omnited tables

Best regards Adam

feature: return dump as string

Hi, I want to use MySqlDump in a shared hosted of a client that doesn't allows me to write to files (also doesn't allows me to run exec to mysqldump)..

It is possible that if the filename parameter is empty instead of writing to a file it will return the dump as a string to get it by http ?

Getting output in variable

Hi, can i get mysqldump output in a variable?
I found a tricky way to do that but is there any simple/quick way to do this?

include_once(dirname(__FILE__) . '/mysqldump-php-1.4.1/src/Ifsnop/Mysqldump/Mysqldump.php');
$dump = new Ifsnop\Mysqldump\Mysqldump( 'database', 'username', 'password');

ob_start();
$dump->start('php://output');
$output = ob_get_contents();
ob_end_clean();

Unzipped file name appears wrong

We ran the script with more-or-less the same settings as in the README.md example. The output filename was "db_dump.sql.gz".

Running from a browser, this saved as "db_dump.gz.gz".

Unzipping this gave us "db_dump.gz", although that was actually an SQL file.

Somewhere the "sql" was being replaced with "gz" in the content disposition attachment filename.

Worked like a charm otherwise - a life-saver when you don't have command-line access to a server :-)

Failed to restore views

When I import the backup, I get an error on the order in which the views were written in the SQL file, there are views that depend on other views, I do not get this error when I run mysqldump.

Add several options from mysqldump (add-drop-table, single-transaction, lock-tables, add-locks, extended-insert)

Speed up the dump and the insertion of data by adding the following settings before exporting:

  • add-drop-table: Add a DROP TABLE statement before each CREATE TABLE statement.
  • single-transaction: This option sets the transaction isolation mode to REPEATABLE READ and sends a START TRANSACTION SQL statement to the server before dumping data. It is useful only with transactional tables such as InnoDB, because then it dumps the consistent state of the database at the time when START TRANSACTION was issued without blocking any applications.
  • lock-tables: For each dumped database, lock all tables to be dumped before dumping them. The tables are locked with READ LOCAL to permit concurrent inserts in the case of MyISAM tables. For transactional tables such as InnoDB, --single-transaction is a much better option than --lock-tables because it does not need to lock the tables at all.
  • add-locks: Surround each table dump with LOCK TABLES and UNLOCK TABLES statements. This results in faster inserts when the dump file is reloaded. See Section 8.3.2.1, “Speed of INSERT Statements”.
  • extended-insert: Use multiple-row INSERT syntax that include several VALUES lists. This results in a smaller dump file and speeds up inserts when the file is reloaded.

Skip table structure.

Hey, Thanks guys for your work on this project,
Don't you think it would be nice to be able to export only the data, and skip the table structure ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.