mysqldump [options] [db_name [tbl_name ...]]
Dump a database or a collection of
databases for backup or transfer to another SQL server (not necessarily a MySQL server).
original web page
by default contains SQL statements to create the table, populate it, or both.
Can generate files in CSV, other delimited text, or XML format.
mysqldump [options] db_name [tbl_name …]
mysqldump [options] --databases db_name …
mysqldump [options] --all-databases
Example:
mysqldump dauser_moodle MHS_tbl --user=dauser_uname --password --compact > MSH.`date +%y%m%d`.dump
Omitting table names or with --databases
or --all-databases
, entire databases are dumped.
To include INFORMATION_SCHEMA
†
explicitly include it on the command line, and use --skip-lock-tables
.
In MySQL Cluster NDB 7.1.7 and later, the ndbinfo information database is ignored and not dumped by mysqldump.
Some options are shorthand for groups of others
--user=user_name |
To reverse the effect of a group option, uses its --skip-xxx
form (--skip-opt
or --skip-compact
).
Or select only part of the effect of a group option by following it with options that enable or disable specific features.
Examples:
To select the effect of --opt
except for some features, use the --skip
option for each feature.
To disable extended inserts and memory buffering, use --skip-extended-insert --skip-quick
.
To reverse --opt
for all features except index disabling
and table locking
, use --skip-opt --disable-keys --lock-tables
.
Order is important because options are processed first to last.
For example, --disable-keys --lock-tables --skip-opt
would not have the intended effect; it is the same as --skip-opt
by itself.
mysqldump can retrieve and dump table contents row by row, or it can retrieve the entire content from a table and buffer it in memory
before dumping it. Buffering in memory can be a problem with large tables.
To enable memory buffering, use --skip-quick
.
The initial size of the buffer for client/server communication. When creating multiple-row INSERT
statements (as with the
--extended-insert or --opt option), mysqldump creates rows up to net_buffer_length length. If you increase this variable, you
should also ensure that the net_buffer_length variable in the MySQL server is at least this large.
set variables using --varname=value
syntax:
--net_buffer_length=nnn
--max_allowed_packet=nnnn
buffer for client/server communication. maximum is 1GB.
> mysqldump db_name > backup-file.sql
Load the dump file into a server :
> mysql db_name < backup-file.sql
Or
> mysql -e "source /path-to-backup/backup-file.sql" db_name
Copy data from one server to another:
> mysqldump --opt db_name | mysql --host=remote_host -C db_name
Dump several databases with one command:
> mysqldump --databases db_name1 [db_name2 ...] > my_databases.sql
To dump all databases, use the --all-databases option:
> mysqldump --all-databases > all_databases.sql
For InnoDB tables, mysqldump provides a way of making an online backup:
shell> mysqldump --all-databases --single-transaction > all_databases.sql
This backup acquires a global read lock on all tables (using FLUSH TABLES WITH READ LOCK) at the beginning of the dump. As soon as this lock has been acquired, the binary log coordinates are read and the lock is released. If long updating statements are running when the FLUSH statement is issued, the MySQL server may get stalled until those statements finish. After that, the dump becomes lock free and does not disturb reads and writes on the tables. If the update statements that the MySQL server receives are short (in terms of execution time), the initial lock period should not be noticeable, even with many updates.
For point-in-time recovery (also known as "roll-forward," when you need to restore an old backup and replay the changes that happened since that backup), it is often useful to rotate the binary log (see Section 5.2.4, "The Binary Log") or at least know the binary log coordinates to which the dump corresponds:
> mysqldump --all-databases --master-data=2 > all_databases.sql
Or:
> mysqldump --all-databases --flush-logs --master-data=2 > all_databases.sql
The --master-data and --single-transaction options can be used simultaneously, which provides a convenient way to make an online backup suitable for use prior to point-in-time recovery if tables are stored using the InnoDB storage engine.
For more information on making backups, see Section 6.2, "Database Backup Methods", and Section 6.3, "Example Backup and Recovery Strategy".
If you encounter problems backing up views, read the section that covers restrictions on views which describes a workaround for backing up views when this fails due to insufficient privileges. See Section E.4, "Restrictions on Views".
Original
Copyright © 1997, 2011, Oracle and/or its affiliates. All rights reserved.
This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see http://www.gnu.org/licenses/.
NOTES 1. Bug#30123 http://bugs.mysql.com/bug.php?id=30123
SEE ALSO For more information, please refer to the MySQL Reference Manual, which may already be installed locally and which is also available online at http://dev.mysql.com/doc/.
original AUTHOR: Oracle Corporation dev.mysql.com
MySQL 5.1 02/11/2011 MYSQLDUMP(1)
/usr/bin > mysqldump --help mysqldump Ver 10.13 Distrib 5.1.56, for unknown-linux-gnu (x86_64) By Igor Romanenko, Monty, Jani & Sinisa. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license. Dumping structure and contents of MySQL databases and tables. Usage: mysqldump [OPTIONS] database [tables] OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...] OR mysqldump [OPTIONS] --all-databases [OPTIONS]Default options are read from the following files in the given order: /etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf The following groups are read: mysqldump client The following options may be given as the first argument: --print-defaults Print the program argument list and exit. --no-defaults Don't read default options from any option file. --defaults-file=# Only read default options from the given file #. --defaults-extra-file=# Read this file after the global files are read. --all Deprecated. Use --create-options instead. -A, --all-databases Dump all the databases. This will be same as --databases with all databases selected. -Y, --all-tablespaces Dump all the tablespaces. -y, --no-tablespaces Do not dump any tablespace information. --add-drop-database Add a DROP DATABASE before each create. --add-drop-table Add a DROP TABLE before each create. --add-locks Add locks around INSERT statements. --allow-keywords Allow creation of column names that are keywords. --character-sets-dir=name Directory for character set files. -i, --comments Write additional information. --compatible=name Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires MySQL server version 4.1.0 or higher. ignored with earlier server versions. --compact Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --skip-add-locks --skip-comments --skip-disable-keys --skip-set-charset. -c, --complete-insert Use complete insert statements. -C, --compress Use compression in server/client protocol. -a, --create-options Include all MySQL specific create options. -B, --databases Dump several databases. Note the difference in usage; in this case no tables are given. All name arguments are regarded as database names. 'USE db_name;' will be included in the output. -#, --debug[=#] This is a non-debug version. Catch this and exit. --debug-check Check memory and open file usage at exit. --debug-info Print some debug info at exit. --default-character-set=name Set the default character set. --delayed-insert Insert rows with INSERT DELAYED. --delete-master-logs Delete logs on master after backup. This automatically enables --master-data. -K, --disable-keys '/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output. -E, --events Dump events. -e, --extended-insert Use multiple-row INSERT syntax that include several VALUES lists. --fields-terminated-by=name Fields in the output file are terminated by the given string. --fields-enclosed-by=name Fields in the output file are enclosed by the given character. --fields-optionally-enclosed-by=name Fields in the output file are optionally enclosed by the given character. --fields-escaped-by=name Fields in the output file are escaped by the given character. --first-slave Deprecated, renamed to --lock-all-tables. -F, --flush-logs Flush logs file in server before starting dump. Note that if you dump many databases at once (using the option --databases= or --all-databases), the logs will be flushed for each database dumped. The exception is when using --lock-all-tables or --master-data: in this case the logs will be flushed only once, corresponding to the moment all tables are locked. So if you want your dump and the log flush to happen at the same exact moment you should use --lock-all-tables or --master-data with --flush-logs. --flush-privileges Emit a FLUSH PRIVILEGES statement after dumping the mysql database. used any time the dump contains the mysql database and any other database that depends on the data in the mysql database for proper restore. -f, --force Continue even if we get an SQL error. -?, --help Display this help message and exit. --hex-blob Dump binary strings (BINARY, VARBINARY, BLOB) in hexadecimal format. -h, --host=name Connect to host. --ignore-table=name Do not dump the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. Each table must be specified with both database and table names, e.g., --ignore-table=database.table. --insert-ignore Insert rows with INSERT IGNORE. --lines-terminated-by=name Lines in the output file are terminated by the given string. -x, --lock-all-tables Locks all tables across all databases. This is achieved by taking a global read lock for the duration of the whole dump. Automatically turns --single-transaction and --lock-tables off. -l, --lock-tables Lock all tables for read. --log-error=name Append warnings and errors to given file. --master-data[=#] This causes the binary log position and filename to be appended to the output. If equal to 1, will print it as a CHANGE MASTER command; if equal to 2, that command will be prefixed with a comment symbol. This option will turn --lock-all-tables on, unless --single-transaction is specified too (in which case a global read lock is only taken a short time at the beginning of the dump; don't forget to read about --single-transaction below). In all cases, any action on logs will happen at the exact moment of the dump. Option automatically turns --lock-tables off. --max_allowed_packet=# The maximum packet length to send to or receive from server. --net_buffer_length=# The buffer size for TCP/IP and socket communication. --no-autocommit Wrap tables with autocommit/commit statements. -n, --no-create-db Suppress the CREATE DATABASE ... IF EXISTS statement that normally is output for each dumped database if --all-databases or --databases is given. -t, --no-create-info Don't write table creation info. -d, --no-data No row information. -N, --no-set-names Suppress the SET NAMES statement --opt Same as --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. Enabled by default, disable with --skip-opt. --order-by-primary Sorts each table's rows by primary key, or first unique key, if such a key exists. Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer. -p, --password[=name] Password to use when connecting to server. If password is not given it's solicited on the tty. -P, --port=# Port number to use for connection. --protocol=name The protocol to use for connection (tcp, socket, pipe, memory). -q, --quick Don't buffer query, dump directly to stdout. -Q, --quote-names Quote table and column names with backticks (`). --replace Use REPLACE INTO instead of INSERT INTO. -r, --result-file=name Direct output to a given file. Used in MSDOS, because it prevents new line '\n' from being converted to '\r\n' (carriage return + line feed). -R, --routines Dump stored routines (functions and procedures). --set-charset Add 'SET NAMES default_character_set' to the output. Enabled by default; suppress with --skip-set-charset. -O, --set-variable=name Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value. --single-transaction Creates a consistent snapshot by dumping all tables in a single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log position), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them. Option automatically turns off --lock-tables. --dump-date Put a dump date to the end of the output. --skip-opt Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys. -S, --socket=name The socket file to use for connection. --ssl Enable SSL for connection (automatically enabled with other flags).Disable with --skip-ssl. --ssl-ca=name CA file in PEM format (check OpenSSL docs, implies --ssl). --ssl-capath=name CA directory (check OpenSSL docs, implies --ssl). --ssl-cert=name X509 cert in PEM format (implies --ssl). --ssl-cipher=name SSL cipher to use (implies --ssl). --ssl-key=name X509 key in PEM format (implies --ssl). --ssl-verify-server-cert Verify server's "Common Name" in its cert against hostname used when connecting. Disabled by default. -T, --tab=name Create tab-separated textfile for each table to given path. (Create .sql and .txt files.) NOTE: This only works if mysqldump is run on the same machine as the mysqld server. --tables Overrides option --databases (-B). --triggers Dump triggers for each dumped table. --tz-utc SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones. -u, --user=name User for login if not current user. -v, --verbose Print info about the various stages. -V, --version Output version information and exit. -w, --where=name Dump only selected records. Quotes are mandatory. -X, --xml Dump a database as well formed XML.
Variables (--variable-name=value) and boolean options {FALSE|TRUE} Value (after reading options) --------------------------------- -----------------------------
all TRUE all-databases FALSE all-tablespaces FALSE no-tablespaces FALSE add-drop-database FALSE add-drop-table TRUE add-locks TRUE allow-keywords FALSE character-sets-dir (No default value) comments TRUE compatible (No default value) compact FALSE complete-insert FALSE compress FALSE create-options TRUE databases FALSE debug-check FALSE debug-info FALSE default-character-set utf8 delayed-insert FALSE delete-master-logs FALSE disable-keys TRUE events FALSE extended-insert TRUE | fields-terminated-by (No default value) fields-enclosed-by (No default value) fields-optionally-enclosed-by(No default value) fields-escaped-by (No default value) first-slave FALSE flush-logs FALSE flush-privileges FALSE force FALSE hex-blob FALSE host (No default value) insert-ignore FALSE lines-terminated-by (No default value) lock-all-tables FALSE lock-tables TRUE log-error (No default value) master-data 0 max_allowed_packet 25165824 net_buffer_length 1046528 no-autocommit FALSE no-create-db FALSE no-create-info FALSE no-data FALSE | order-by-primary FALSE port 0 quick TRUE quote-names TRUE replace FALSE routines FALSE set-charset TRUE single-transaction FALSE dump-date TRUE socket (No default value) ssl FALSE ssl-ca (No default value) ssl-capath (No default value) ssl-cert (No default value) ssl-cipher (No default value) ssl-key (No default value) ssl-verify-server-cert FALSE tab (No default value) triggers TRUE tz-utc TRUE user (No default value) verbose FALSE where (No default value) |