<?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>Will Fitch&#039;s Blog &#187; mysqldump</title>
	<atom:link href="http://www.willfitch.com/tag/mysqldump/feed" rel="self" type="application/rss+xml" />
	<link>http://www.willfitch.com</link>
	<description></description>
	<lastBuildDate>Sun, 11 Dec 2011 23:39:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Using the mysqldump tool</title>
		<link>http://www.willfitch.com/using-the-mysqldump-tool.html</link>
		<comments>http://www.willfitch.com/using-the-mysqldump-tool.html#comments</comments>
		<pubDate>Tue, 28 Mar 2006 19:55:38 +0000</pubDate>
		<dc:creator>Will Fitch</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>

		<guid isPermaLink="false">http://127615032</guid>
		<description><![CDATA[This tutorial will cover using the mysqldump executable for backing up databases. If you are an average user of MySQL, and are not interested in administering a MySQL server, then this tutorial might be useless to you. The mysqldump tool is a backup program that is distributed with every MySQL download. If you aren&#8217;t familiar [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial will cover using the mysqldump executable for backing up databases.  If you are an average user of MySQL, and are not interested in administering a MySQL server, then this tutorial might be useless to you.</p>
<p><span style="font-family: Verdana">The <span style="font-weight:bold; font-family: Verdana">mysqldump</span></span><span style="font-family: Verdana"> tool is a backup program that is distributed with every MySQL download. If you aren&#8217;t familiar with the bin directory within your MySQL distro, then it&#8217;s time to start playing around with the tools inside it. </span></p>
<p><span style="font-family: Verdana">According to MySQL AB, a man named Igor Romanenko was the original author of the </span><span style="font-weight:bold; font-family: Verdana">mysqldump</span><span style="font-family: Verdana"> tool. As with all software, especially open source, it has been hacked, smacked, slapped around and rewritten 17 times since then (those aren&#8217;t actual statistics). When using the </span><span style="font-weight:bold; font-family: Verdana">mysqldump</span><span style="font-family: Verdana"> tool, it produces SQL statements to create table structure, populate tables, or both. </span></p>
<p><span style="font-family: Verdana">I will assume you are using Linux command line to practice using this tool, but the same principles apply to Windows. Please do not play with production data if this is your first time using this application. You can screw things up if you aren&#8217;t careful.</span></p>
<p><span style="font-family: Verdana">The first step is to get into the MySQL bin directory. If your installation of MySQL is in /usr/local/mysql, then let&#8217;s get there by typing the following:</span></p>
<p><strong><span style="font-family: Georgia">cd /usr/local/mysql/bin</span></strong></p>
<p><span style="font-family: Verdana">Now that we are inside our bin directory, let&#8217;s list the files within and see what we&#8217;ve got.</span></p>
<p><strong><span style="font-family: Georgia">ls</span></strong></p>
<p><span style="font-family: Verdana">Now you should see the </span><span style="font-weight:bold; font-family: Verdana">mysqldump</span><span style="font-family: Verdana"> tool along with a bunch of other stuff that will eventually get covered in other tutorials. Although we are only going to cover the commonly used and mostly basic options, letâ€™s look at all that can be used with </span><span style="font-weight:bold; font-family: Verdana">mysqldump</span><span style="font-family: Verdana">. Click <a href="http://www.phpfever.com/uploads/mysqldump_options.txt" target="_blank">here</a> to view them.</span></p>
<p><span style="font-family: Verdana">The command to backup an entire database is simple:</span></p>
<p><strong><span style="font-family: Georgia">mysqldump database_name &gt; filename_to_create.sql</span></strong></p>
<p><span style="font-family: Verdana">Keep in mind that you will likely be required to use the â€“p (password) and/or â€“u (username) to backup a database. That user must have permissions to access that particular database. For instance, if we needed to backup the mysql database, and were using the root user, we would type the following:</span></p>
<p><strong><span style="font-family: Georgia">mysqldump mysql &gt; mysql_backup.sql â€“u root â€“p</span></strong></p>
<p><span style="font-family: Verdana">At this point, MySQL will prompt us to input a password for the user root. After doing so, the backup process will begin, and a new file filled with all of the SQL creations and inserts for the mysql database will be available. Pretty handy, huh? What if we need to backup <strong>ALL </strong>databases? This is actually just as simple! </span></p>
<p><span style="font-family: Verdana">With the list of options provided with the link above, one of the option was â€œ&#8211;all-databasesâ€. This will dump all databases into the file you command. Letâ€™s try it!</span></p>
<p><strong><span style="font-family: Georgia">mysqldump â€“all-databases &gt; alldbs.sql â€“u root â€“p</span></strong></p>
<p><span style="font-family: Verdana">This will dump all databases into an SQL file called alldbs.sql. Now that we have finally backed up some databases, what do we need to do to restore them? </span></p>
<p><span style="font-family: Verdana">This can actually be a little tricky at first. You wonâ€™t be using </span><span style="font-weight:bold; font-family: Verdana">mysqldump</span><span style="font-family: Verdana"> to do this, but rather mysql itself. There are two possible ways to do this. The first is to restore the data directly (using brute force). I donâ€™t like this way, and if the SQL is formatted <strong>perfectly</strong>, then you could run into some issues. At all costs, here is the format:</span></p>
<p><strong><span style="font-family: Georgia">mysql db_name &lt; file.sql</span></strong></p>
<p><span style="font-family: Verdana">Again, permissions will be a factor here. <span></span>Here is my favorite method:</span></p>
<p><strong><span style="font-family: Georgia">mysql â€“e â€œsource backup_file.sqlâ€ db_name</span></strong></p>
<p><span style="font-family: Verdana">Thatâ€™s it! That is way too easy. </span></p>
<p><span style="font-family: Verdana">Before closing this tutorial, I want to show you how to copy databases and their data from one server to another. This is extremely handy if you have a development, test, and production area serving different databases:</span></p>
<pre><strong><span style="background: white none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: windowtext; font-family: Georgia" lang="EN">mysqldump â€“opt db_name | mysql â€“host=remote_host -C db_name</span></strong></pre>
<pre><span style="font-family: Verdana">The </span><span style="font-weight:bold; font-family: Verdana">mysqldump</span><span style="font-family: Verdana"> tool is just too cool!  If you have any questions, feel free to email me.</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.willfitch.com/using-the-mysqldump-tool.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

