<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dreamvib ~ music lounge &#187; linux</title>
	<atom:link href="http://music.dreamvib.com/category/programming/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://music.dreamvib.com</link>
	<description></description>
	<lastBuildDate>Fri, 12 Jun 2009 08:31:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>mysqldump</title>
		<link>http://music.dreamvib.com/programming/mysql/mysqldump/</link>
		<comments>http://music.dreamvib.com/programming/mysql/mysqldump/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 08:05:53 +0000</pubDate>
		<dc:creator>dreamvib</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://blog.dreamvib.com/?p=14</guid>
		<description><![CDATA[Name
mysqldump &#8211; a database backup program
Synopsis

mysqldump [options] [db_name [tbl_name ...]]

Description
The mysqldump client is a backup program originally written by Igor Romanenko. It can be used to dump a database or a collection of databases for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump contains SQL statements [...]]]></description>
			<content:encoded><![CDATA[<h2>Name</h2>
<p>mysqldump &#8211; a database backup program</p>
<h2>Synopsis</h2>
<dl compact="compact">
<dt><strong>mysqldump [<em>options</em>] [<em>db_name</em> [<em>tbl_name</em> ...]]</strong></dt>
</dl>
<h2>Description</h2>
<p>The <strong>mysqldump</strong> client is a backup program originally written by Igor Romanenko. It can be used to <span class="highlight1">dump</span> a database or a collection of databases for backup or for transferring the data to another SQL server (not necessarily a <span class="highlight0">MySQL</span> server). The <span class="highlight1">dump</span> contains SQL statements to create the table or populate it, or both.</p>
<p>If you are doing a backup on the server, and your tables all are MyISAM tables, consider using the <strong>mysqlhotcopy</strong> instead because it can accomplish faster backups and faster restores. See <em><strong><a href="http://linux.die.net/man/1/mysqlhotcopy" rel="nofollow">mysqlhotcopy</a></strong>(1)</em>.</p>
<p>There are three general ways to invoke <strong>mysqldump</strong>:</p>
<pre class="code">shell&gt; mysqldump [options] db_name [tables]
shell&gt; mysqldump [options] --databases db_name1 [db_name2 db_name3...]
shell&gt; mysqldump [options] --all-databases</pre>
<p>If you do not name any tables following <em>db_name</em> or if you use the <strong>&#8211;databases</strong> or <strong>&#8211;all-databases</strong> option, entire databases are dumped.To get a list of the options your version of <strong>mysqldump</strong> supports, execute <strong>mysqldump &#8211;help</strong>.</p>
<p>If you run <strong>mysqldump</strong> without the <strong>&#8211;quick</strong> or <strong>&#8211;opt</strong> option, <strong>mysqldump</strong> loads the whole result set into memory before dumping the result. This can be a problem if you are dumping a big database. The <strong>&#8211;opt</strong> option is enabled by default, but can be disabled with <strong>&#8211;skip-opt</strong>.</p>
<p>If you are using a recent copy of the <strong>mysqldump</strong> program to generate a <span class="highlight1">dump</span> to be reloaded into a very old <span class="highlight0">MySQL</span> server, you should not use the <strong>&#8211;opt</strong> or <strong>&#8211;extended-insert</strong> option. Use <strong>&#8211;skip-opt</strong> instead.</p>
<p><strong>mysqldump</strong> supports the following options:</p>
<ul>
<li><strong>&#8211;help</strong>, <strong>-?</strong>Display a help message and exit.</li>
<li><strong>&#8211;add-drop-database</strong>Add a DROP DATABASE statement before each CREATE DATABASE statement.</li>
<li><strong>&#8211;add-drop-table</strong>Add a DROP TABLE statement before each CREATE TABLE statement.</li>
<li><strong>&#8211;add-locks</strong>Surround each table <span class="highlight1">dump</span> with LOCK TABLES and UNLOCK TABLES statements. This results <span class="highlight2">in</span> faster inserts when the <span class="highlight1">dump</span> file is reloaded. See Section 2.16, lqSpeed of INSERT Statementsrq.</li>
<li><strong>&#8211;all-databases</strong>, <strong>-A</strong><span class="highlight1">Dump</span> all tables <span class="highlight2">in</span> all databases. This is the same as using the <strong>&#8211;databases</strong> option and naming all the databases on the command line.</li>
<li><strong>&#8211;allow-keywords</strong>Allow creation of column names that are keywords. This works by prefixing each column name with the table name.</li>
<li><strong>&#8211;character-sets-dir=<em>path</em></strong>The directory where character sets are installed. See Section 9.1, lqThe Character Set Used for Data and Sortingrq.</li>
<li><strong>&#8211;comments</strong>, <strong>-i</strong>Write additional information <span class="highlight2">in</span> the <span class="highlight1">dump</span> file such as program version, server version, and host. . This option is enabled by default. To suppress additional, use <strong>&#8211;skip-comments</strong>.</li>
<li><strong>&#8211;compact</strong>Produce less verbose output. This option suppresses comments and enables the <strong>&#8211;skip-add-drop-table</strong>, <strong>&#8211;no-set-names</strong>, <strong>&#8211;skip-disable-keys</strong>, and <strong>&#8211;skip-add-locks</strong> options.</li>
<li><strong>&#8211;compatible=<em>name</em></strong>Produce output that is more compatible with other database systems or with older <span class="highlight0">MySQL</span> servers. The value of name can be ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, or no_field_options. To use several values, separate them by commas. These values have the same meaning as the corresponding options for setting the server SQL mode. See the section called lqTHE SERVER SQL MODErq.
<p>This option does not guarantee compatibility with other servers. It only enables those SQL mode values that are currently available for making <span class="highlight1">dump</span> output more compatible. For example, <strong>&#8211;compatible=oracle</strong> does not map data types to Oracle types or use Oracle comment syntax.</li>
<li><strong>&#8211;complete-insert</strong>, <strong>-c</strong>Use complete INSERT statements that include column names.</li>
<li><strong>&#8211;compress</strong>, <strong>-C</strong>Compress all information sent between the client and the server if both support compression.</li>
<li><strong>&#8211;create-options</strong>Include all <span class="highlight0">MySQL</span>-specific table options <span class="highlight2">in</span> the CREATE TABLE statements.</li>
<li><strong>&#8211;databases</strong>, <strong>-B</strong><span class="highlight1">Dump</span> several databases. Normally, <strong>mysqldump</strong> treats the first name argument on the command line as a database name and following names as table names. With this option, it treats all name arguments as database names. CREATE DATABASE and USE statements are included <span class="highlight2">in</span> the output before each new database.</li>
<li><strong>&#8211;debug[=<em>debug_options</em>]</strong>, <strong>-# [<em>debug_options</em>]</strong>Write a debugging log. The <em>debug_options</em> string is often &#8216;d:t:o,<em>file_name</em>&#8216;. The default is &#8216;d:t:o,/tmp/mysqldump.trace&#8217;.</li>
<li><strong>&#8211;default-character-set=<em>charset_name</em></strong>Use <em>charset_name</em> as the default character set. See Section 9.1, lqThe Character Set Used for Data and Sortingrq. If not specified, <strong>mysqldump</strong> uses utf8.</li>
<li><strong>&#8211;delayed-insert</strong>Write INSERT DELAYED statements rather than INSERT statements.</li>
<li><strong>&#8211;delete-master-logs</strong>On a master replication server, delete the binary logs after performing the <span class="highlight1">dump</span> operation. This option automatically enables <strong>&#8211;master-data</strong>.</li>
<li><strong>&#8211;disable-keys</strong>, <strong>-K</strong>For each table, surround the INSERT statements with /*!40000 ALTER TABLE <em>tbl_name</em> DISABLE KEYS */; and /*!40000 ALTER TABLE <em>tbl_name</em> ENABLE KEYS */; statements. This makes loading the <span class="highlight1">dump</span> file faster because the indexes are created after all rows are inserted. This option is effective for MyISAM tables only.</li>
<li><strong>&#8211;extended-insert</strong>, <strong>-e</strong>Use multiple-row INSERT syntax that include several VALUES lists. This results <span class="highlight2">in</span> a smaller <span class="highlight1">dump</span> file and speeds up inserts when the file is reloaded.</li>
<li><strong>&#8211;fields-terminated-by=&#8230;</strong>, <strong>&#8211;fields-enclosed-by=&#8230;</strong>, <strong>&#8211;fields-optionally-enclosed-by=&#8230;</strong>, <strong>&#8211;fields-escaped-by=&#8230;</strong>, <strong>&#8211;lines-terminated-by=&#8230;</strong>These options are used with the <strong>-T</strong> option and have the same meaning as the corresponding clauses for LOAD DATA INFILE. See Section 2.5, lqLOAD DATA INFILE Syntaxrq.</li>
<li><strong>&#8211;first-slave</strong>, <strong>-x</strong>Deprecated. Now renamed to <strong>&#8211;lock-all-tables</strong>.</li>
<li><strong>&#8211;flush-logs</strong>, <strong>-F</strong>Flush the <span class="highlight0">MySQL</span> server log files before starting the <span class="highlight1">dump</span>. This option requires the RELOAD privilege. Note that if you use this option <span class="highlight2">in</span> combination with the <strong>&#8211;all-databases</strong> (or <strong>-A</strong>) option, the logs are flushed <em>for each database dumped</em>. The exception is when using <strong>&#8211;lock-all-tables</strong> or <strong>&#8211;master-data</strong>: <span class="highlight2">In</span> this case, the logs are flushed only once, corresponding to the moment that all tables are locked. If you want your <span class="highlight1">dump</span> and the log flush to happen at exactly the same moment, you should use <strong>&#8211;flush-logs</strong> together with either <strong>&#8211;lock-all-tables</strong> or <strong>&#8211;master-data</strong>.</li>
<li><strong>&#8211;force</strong>, <strong>-f</strong>Continue even if an SQL error occurs during a table <span class="highlight1">dump</span>.</li>
<li><strong>&#8211;host=<em>host_name</em></strong>, <strong>-h <em>host_name</em></strong><span class="highlight1">Dump</span> data from the <span class="highlight0">MySQL</span> server on the given host. The default host is localhost.</li>
<li><strong>&#8211;hex-blob</strong><span class="highlight1">Dump</span> binary columns using hexadecimal notation (for example, &#8216;abc&#8217; becomes 0&#215;616263). The affected data types are BINARY, VARBINARY, and BLOB. As of <span class="highlight0">MySQL</span> 5.0.13, BIT columns are affected as well.</li>
<li><strong>&#8211;ignore-table=<em>db_name.tbl_name</em></strong>Do not <span class="highlight1">dump</span> the given table, which must be specified using both the database and table names. To ignore multiple tables, use this option multiple times.</li>
<li><strong>&#8211;insert-ignore</strong>Write INSERT statements with the IGNORE option.</li>
<li><strong>&#8211;lock-all-tables</strong>, <strong>-x</strong>Lock all tables across all databases. This is achieved by acquiring a global read lock for the duration of the whole <span class="highlight1">dump</span>. This option automatically turns off <strong>&#8211;single-transaction</strong> and <strong>&#8211;lock-tables</strong>.</li>
<li><strong>&#8211;lock-tables</strong>, <strong>-l</strong>Lock all tables before starting the <span class="highlight1">dump</span>. The tables are locked with READ LOCAL to allow concurrent inserts <span class="highlight2">in</span> the case of MyISAM tables. For transactional tables such as InnoDB and BDB, <strong>&#8211;single-transaction</strong> is a much better option, because it does not need to lock the tables at all.
<p>Please note that when dumping multiple databases, <strong>&#8211;lock-tables</strong> locks tables for each database separately. So, this option does not guarantee that the tables <span class="highlight2">in</span> the <span class="highlight1">dump</span> file are logically consistent between databases. Tables <span class="highlight2">in</span> different databases may be dumped <span class="highlight2">in</span> completely different states.</li>
<li><strong>&#8211;master-data[=<em>value</em>]</strong>Write the binary log filename and position to the output. This option requires the RELOAD privilege and the binary log must be enabled. If the option value is equal to 1, the position and filename are written to the <span class="highlight1">dump</span> output <span class="highlight2">in</span> the form of a CHANGE MASTER statement that makes a slave server start from the correct position <span class="highlight2">in</span> the master&#8217;s binary logs if you use this SQL <span class="highlight1">dump</span> of the master to set up a slave. If the option value is equal to 2, the CHANGE MASTER statement is written as an SQL comment. This is the default action if <em>value</em> is omitted.
<p>The <strong>&#8211;master-data</strong> option turns on <strong>&#8211;lock-all-tables</strong>, unless <strong>&#8211;single-transaction</strong> also is specified (<span class="highlight2">in</span> which case, a global read lock is only acquired a short time at the beginning of the <span class="highlight1">dump</span>. See also the description for <strong>&#8211;single-transaction</strong>. <span class="highlight2">In</span> all cases, any action on logs happens at the exact moment of the <span class="highlight1">dump</span>. This option automatically turns off <strong>&#8211;lock-tables</strong>.</li>
<li><strong>&#8211;no-autocommit</strong>Enclose the INSERT statements for each dumped table within SET AUTOCOMMIT=0 and COMMIT statements.</li>
<li><strong>&#8211;no-create-db</strong>, <strong>-n</strong>This option suppresses the CREATE DATABASE statements that are otherwise included <span class="highlight2">in</span> the output if the <strong>&#8211;databases</strong> or <strong>&#8211;all-databases</strong> option is given.</li>
<li><strong>&#8211;no-create-info</strong>, <strong>-t</strong>Do not write CREATE TABLE statements that re-create each dumped table.</li>
<li><strong>&#8211;no-data</strong>, <strong>-d</strong>Do not write any row information for the table. This is very useful if you want to <span class="highlight1">dump</span> only the CREATE TABLE statement for the table.</li>
<li><strong>&#8211;opt</strong>This option is shorthand; it is the same as specifying <strong>&#8211;add-drop-table &#8211;add-locks &#8211;create-options &#8211;disable-keys &#8211;extended-insert &#8211;lock-tables &#8211;quick &#8211;set-charset</strong>. It should give you a fast <span class="highlight1">dump</span> operation and produce a <span class="highlight1">dump</span> file that can be reloaded into a <span class="highlight0">MySQL</span> server quickly.
<p><em>The <strong>&#8211;opt</strong> option is enabled by default. To disable the options that it enables, use <strong>&#8211;skip-opt</strong></em>. To disable only certain of the options enabled by <strong>&#8211;opt</strong>, use their <strong>&#8211;skip</strong> forms; for example, <strong>&#8211;skip-add-drop-table</strong> or <strong>&#8211;skip-quick</strong>.</li>
<li><strong>&#8211;order-by-primary</strong>Sorts each table&#8217;s rows by its primary key, or its first unique index, if such an index exists. This is useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the <span class="highlight1">dump</span> itself take considerably longer.</li>
<li><strong>&#8211;password[=<em>password</em>]</strong>, <strong>-p[<em>password</em>]</strong>The password to use when connecting to the server. If you use the short option form (<strong>-p</strong>), you <em>cannot</em> have a space between the option and the password. If you omit the <em>password</em> value following the <strong>&#8211;password</strong> or <strong>-p</strong> option on the command line, you are prompted for one.
<p>Specifying a password on the command line should be considered insecure. See Section 7.6, lqKeeping Your Password Securerq.</li>
<li style="list-style-type: none; list-style-image: none; list-style-position: outside">Â·</li>
<li><strong>&#8211;port=<em>port_num</em></strong>, <strong>-P <em>port_num</em></strong>The TCP/IP port number to use for the connection.</li>
<li><strong>&#8211;protocol={TCP|SOCKET|PIPE|MEMORY}</strong>The connection protocol to use.</li>
<li><strong>&#8211;quick</strong>, <strong>-q</strong>This option is useful for dumping large tables. It forces <strong>mysqldump</strong> to retrieve rows for a table from the server a row at a time rather than retrieving the entire row set and buffering it <span class="highlight2">in</span> memory before writing it out.</li>
<li><strong>&#8211;quote-names</strong>, <strong>-Q</strong>Quote database, table, and column names within oq&#8217;cq characters. If the ANSI_QUOTES SQL mode is enabled, names are quoted within oq&#8221;cq characters. This option is enabled by default. It can be disabled with <strong>&#8211;skip-quote-names</strong>, but this option should be given after any option such as <strong>&#8211;compatible</strong> that may enable <strong>&#8211;quote-names</strong>.</li>
<li><strong>&#8211;result-file=<em>file</em></strong>, <strong>-r <em>file</em></strong>Direct output to a given file. This option should be used on Windows to prevent newline oq\ncq characters from being converted to oq\r\ncq carriage return/newline sequences.</li>
<li><strong>&#8211;routines</strong>, <strong>-R</strong><span class="highlight1">Dump</span> stored routines (functions and procedures) from the dumped databases. The output generated by using <strong>&#8211;routines</strong> contains CREATE PROCEDURE and CREATE FUNCTION statements to re-create the routines. However, these statements do not include attributes such as the routine creation and modification timestamps. This means that when the routines are reloaded, they will be created with the timestamps equal to the reload time.
<p>If you require routines to be re-created with their original timestamp attributes, do not use <strong>&#8211;routines</strong>. Instead, <span class="highlight1">dump</span> and reload the contents of the <span class="highlight0">mysql</span>.proc table directly, using a <span class="highlight0">MySQL</span> account that has appropriate privileges for the <span class="highlight0">mysql</span> database.</p>
<p>This option was added <span class="highlight2">in</span> <span class="highlight0">MySQL</span> 5.0.13. Before that, stored routines are not dumped. Routine DEFINER values are not dumped until <span class="highlight0">MySQL</span> 5.0.20. This means that before 5.0.20, when routines are reloaded, they will be created with the definer set to the reloading user. If you require routines to be re-created with their original definer, <span class="highlight1">dump</span> and load the contents of the <span class="highlight0">mysql</span>.proc table directly as described earlier.</li>
<li><strong>&#8211;set-charset</strong>Add SET NAMES <em>default_character_set</em> to the output. This option is enabled by default. To suppress the SET NAMES statement, use <strong>&#8211;skip-set-charset</strong>.</li>
<li><strong>&#8211;single-transaction</strong>This option issues a BEGIN SQL statement before dumping data from the server. It is useful only with transactional tables such as InnoDB and BDB, because then it <span class="highlight1">dumps</span> the consistent state of the database at the time when BEGIN was issued without blocking any applications.
<p>When using this option, you should keep <span class="highlight2">in</span> mind that only InnoDB tables are dumped <span class="highlight2">in</span> a consistent state. For example, any MyISAM or MEMORY tables dumped while using this option may still change state.</p>
<p>The <strong>&#8211;single-transaction</strong> option and the <strong>&#8211;lock-tables</strong> option are mutually exclusive, because LOCK TABLES causes any pending transactions to be committed implicitly.</p>
<p>To <span class="highlight1">dump</span> big tables, you should combine this option with <strong>&#8211;quick</strong>.</li>
<li><strong>&#8211;socket=<em>path</em></strong>, <strong>-S <em>path</em></strong>For connections to localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.</li>
<li><strong>&#8211;skip-comments</strong>See the description for the <strong>&#8211;comments</strong> option.</li>
<li><strong>&#8211;ssl*</strong>Options that begin with <strong>&#8211;ssl</strong> specify whether to connect to the server via SSL and indicate where to find SSL keys and certificates. See Section 7.7.3, lqSSL Command Optionsrq.</li>
<li style="list-style-type: none; list-style-image: none; list-style-position: outside">Â·</li>
<li><strong>&#8211;tab=<em>path</em></strong>, <strong>-T <em>path</em></strong>Produce tab-separated data files. For each dumped table, <strong>mysqldump</strong> creates a <em>tbl_name.sql</em> file that contains the CREATE TABLE statement that creates the table, and a <em>tbl_name.txt</em> file that contains its data. The option value is the directory <span class="highlight2">in</span> which to write the files.
<p>By default, the <em>.txt</em> data files are formatted using tab characters between column values and a newline at the end of each line. The format can be specified explicitly using the <strong>&#8211;fields-<em>xxx</em></strong> and <strong>&#8211;lines&#8211;<em>xxx</em></strong> options.</p>
<p><strong>Note</strong>: This option should be used only when <strong>mysqldump</strong> is run on the same machine as the <strong>mysqld</strong> server. You must have the FILE privilege, and the server must have permission to write files <span class="highlight2">in</span> the directory that you specify.</li>
<li><strong>&#8211;tables</strong>Override the <strong>&#8211;databases</strong> or <strong>-B</strong> option. All name arguments following the option are regarded as table names.</li>
<li><strong>&#8211;triggers</strong><span class="highlight1">Dump</span> triggers for each dumped table. This option is enabled by default; disable it with <strong>&#8211;skip-triggers</strong>. This option was added <span class="highlight2">in</span> <span class="highlight0">MySQL</span> 5.0.11. Before that, triggers are not dumped.</li>
<li><strong>&#8211;tz-utc</strong>Add SET TIME_ZONE=&#8217;+00:00&#8242; to the <span class="highlight1">dump</span> file so that TIMESTAMP columns can be dumped and reloaded between servers <span class="highlight2">in</span> different time zones. Without this option, TIMESTAMP columns are dumped and reloaded <span class="highlight2">in</span> the time zones local to the source and destination servers, which can cause the values to change. <strong>&#8211;tz-utc</strong> also protects against changes due to daylight saving time. <strong>&#8211;tz-utc</strong> is enabled by default. To disable it, use <strong>&#8211;skip-tz-utc</strong>. This option was added <span class="highlight2">in</span> <span class="highlight0">MySQL</span> 5.0.15.</li>
<li><strong>&#8211;user=<em>user_name</em></strong>, <strong>-u <em>user_name</em></strong>The <span class="highlight0">MySQL</span> username to use when connecting to the server.</li>
<li><strong>&#8211;verbose</strong>, <strong>-v</strong>Verbose mode. Print more information about what the program does.</li>
<li><strong>&#8211;version</strong>, <strong>-V</strong>Display version information and exit.</li>
<li><strong>&#8211;where=&#8217;<em>where_condition</em>&#8216;</strong>, <strong>-w &#8216;<em>where_condition</em>&#8216;</strong><span class="highlight1">Dump</span> only rows selected by the given WHERE condition. Note that quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.
<p>Examples:</p>
<pre class="code">--where="user='jimf'"
-w"userid&gt;1"
-w"userid&lt;1"</pre>
</li>
<li><strong>&#8211;xml</strong>, <strong>-X</strong>Write <span class="highlight1">dump</span> output as well-formed XML.</li>
</ul>
<p>You can also set the following variables by using <strong>&#8211;<em>var_name</em>=<em>value</em></strong> syntax:</p>
<ul>
<li>max_allowed_packetThe maximum size of the buffer for client/server communication. The maximum is 1GB.</li>
<li>net_buffer_lengthThe initial size of the buffer for client/server communication. When creating multiple-row-insert statements (as with option <strong>&#8211;extended-insert</strong> or <strong>&#8211;opt</strong>), <strong>mysqldump</strong> creates rows up to net_buffer_length length. If you increase this variable, you should also ensure that the net_buffer_length variable <span class="highlight2">in</span> the <span class="highlight0">MySQL</span> server is at least this large.</li>
</ul>
<p>It is also possible to set variables by using <strong>&#8211;set-variable=<em>var_name</em>=<em>value</em></strong> or <strong>-O <em>var_name</em>=<em>value</em></strong> syntax. <em>This syntax is deprecated</em>.</p>
<p>The most common use of <strong>mysqldump</strong> is probably for making a backup of an entire database:</p>
<pre class="code">shell&gt; mysqldump --opt db_name &gt; backup-file.sql</pre>
<p>You can read the <span class="highlight1">dump</span> file back into the server like this:</p>
<pre class="code">shell&gt; <span class="highlight0">mysql</span> db_name &lt; backup-file.sql</pre>
<p>Or like this:</p>
<pre class="code">shell&gt; <span class="highlight0">mysql</span> -e "source /path-to-backup/backup-file.sql" db_name</pre>
<p><strong>mysqldump</strong> is also very useful for populating databases by copying data from one <span class="highlight0">MySQL</span> server to another:</p>
<pre class="code">shell&gt; mysqldump --opt db_name | <span class="highlight0">mysql</span> --host=remote_host -C db_name</pre>
<p>It is possible to <span class="highlight1">dump</span> several databases with one command:</p>
<pre class="code">shell&gt; mysqldump --databases db_name1 [db_name2 ...] &gt; my_databases.sql</pre>
<p>To <span class="highlight1">dump</span> all databases, use the <strong>&#8211;all-databases</strong> option:</p>
<pre class="code">shell&gt; mysqldump --all-databases &gt; all_databases.sql</pre>
<p>For InnoDB tables, mysqldump provides a way of making an online backup:</p>
<pre class="code">shell&gt; mysqldump --all-databases --single-transaction &gt; all_databases.sql</pre>
<p>This backup just needs to acquire a global read lock on all tables (using FLUSH TABLES WITH READ LOCK) at the beginning of the <span class="highlight1">dump</span>. As soon as this lock has been acquired, the binary log coordinates are read and the lock is released. If and only if one long updating statement is running when the FLUSH statement is issued, the <span class="highlight0">MySQL</span> server may get stalled until that long statement finishes, and then the <span class="highlight1">dump</span> becomes lock-free. If the update statements that the <span class="highlight0">MySQL</span> server receives are short (<span class="highlight2">in</span> terms of execution time), the initial lock period should not be noticeable, even with many updates.For point-<span class="highlight2">in</span>-time recovery (also known as lqroll-forward,rq 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 10.3, lqThe Binary Logrq) or at least know the binary log coordinates to which the <span class="highlight1">dump</span> corresponds:</p>
<pre class="code">shell&gt; mysqldump --all-databases --master-data=2 &gt; all_databases.sql</pre>
<p>Or:</p>
<pre class="code">shell&gt; mysqldump --all-databases --flush-logs --master-data=2
              &gt; all_databases.sql</pre>
<p>The simultaneous use of <strong>&#8211;master-data</strong> and <strong>&#8211;single-transaction</strong> provides a convenient way to make an online backup suitable for point-<span class="highlight2">in</span>-time recovery if tables are stored <span class="highlight2">in</span> the InnoDB storage engine.</p>
<p>source: <a href="http://linux.die.net/man/1/mysqldump" target="_blank">http://linux.die.net/man/1/mysqldump</a></p>
]]></content:encoded>
			<wfw:commentRss>http://music.dreamvib.com/programming/mysql/mysqldump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
