<?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>Gary Pendergast &#187; mysqldump</title> <atom:link href="http://pento.net/tag/mysqldump/feed/" rel="self" type="application/rss+xml" /><link>http://pento.net</link> <description>I&#039;m on the Internet</description> <lastBuildDate>Thu, 17 May 2012 04:24:17 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <cloud
domain='pento.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' /> <item><title>Extracting a Database From a mysqldump File</title><link>http://pento.net/2009/04/16/extracting-a-database-from-a-mysqldump-file/</link> <comments>http://pento.net/2009/04/16/extracting-a-database-from-a-mysqldump-file/#comments</comments> <pubDate>Thu, 16 Apr 2009 03:31:55 +0000</pubDate> <dc:creator>Gary</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[mysqldump]]></category> <category><![CDATA[sed]]></category> <guid
isPermaLink="false">http://pento.net/?p=208</guid> <description><![CDATA[Restoring a single database from a full dump is pretty easy, using the mysql command line client&#8217;s --one-database option: mysql&#62; mysql -u root -p --one-database db_to_restore &#60; fulldump.sql But what if you don&#8217;t want to restore the database, you just want to extract it out of the dump file? Well, that happens to be easy [...]]]></description> <content:encoded><![CDATA[<p>Restoring a single database from a full dump is pretty easy, using the <kbd>mysql</kbd> command line client&#8217;s <kbd>--one-database</kbd> option:</p><pre>mysql&gt; mysql -u root -p --one-database db_to_restore &lt; fulldump.sql</pre><p>But what if you don&#8217;t want to restore the database, you just want to extract it out of the dump file? Well, that happens to be easy as well, thanks to the magic of <kbd>sed</kbd>:</p><pre>shell&gt; sed -n '/^-- Current Database: `test`/,/^-- Current Database: `/p' fulldump.sql &gt; test.sql</pre><p>You just need to change &#8220;test&#8221; to be the name of the database you want extracted.</p> ]]></content:encoded> <wfw:commentRss>http://pento.net/2009/04/16/extracting-a-database-from-a-mysqldump-file/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Backing up permissions for individual databases</title><link>http://pento.net/2009/03/12/backing-up-permissions-for-individual-databases/</link> <comments>http://pento.net/2009/03/12/backing-up-permissions-for-individual-databases/#comments</comments> <pubDate>Thu, 12 Mar 2009 01:00:38 +0000</pubDate> <dc:creator>Gary</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[backup]]></category> <category><![CDATA[mysqldump]]></category> <category><![CDATA[permissions]]></category> <category><![CDATA[users]]></category> <guid
isPermaLink="false">http://pento.net/?p=120</guid> <description><![CDATA[Sometimes, you want to backup individual databases in MySQL to move to a different server. This part is easy using mysqldump: shell> mysqldump -u root -p --databases db1 db2 ... > backup.sql The problem is, what happens when you want to backup the permissions associated with these databases? Well, here are a few queries to [...]]]></description> <content:encoded><![CDATA[<p>Sometimes, you want to backup individual databases in MySQL to move to a different server. This part is easy using mysqldump:</p><pre>
shell> mysqldump -u root -p --databases db1 db2 ... > backup.sql
</pre><p>The problem is, what happens when you want to backup the permissions associated with these databases? Well, here are a few queries to help you out.</p><div
class="wp_syntax"><div
class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">-- Grab the users with global permissions, </span>
<span style="color: #808080; font-style: italic;">-- with permissions to the databases you want, </span>
<span style="color: #808080; font-style: italic;">-- and tables/stored procedures in it.</span>
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> u<span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">OUTFILE</span> <span style="color: #ff0000;">'/tmp/user.txt'</span>
	<span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">','</span> <span style="color: #993333; font-weight: bold;">OPTIONALLY</span> <span style="color: #993333; font-weight: bold;">ENCLOSED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'&quot;'</span> <span style="color: #993333; font-weight: bold;">ESCAPED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>
	<span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
	<span style="color: #993333; font-weight: bold;">FROM</span>
		mysql<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span> u
	<span style="color: #993333; font-weight: bold;">WHERE</span>
		u<span style="color: #66cc66;">.</span>Select_priv<span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Y'</span>
	<span style="color: #993333; font-weight: bold;">UNION</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> u<span style="color: #66cc66;">.*</span>
	<span style="color: #993333; font-weight: bold;">FROM</span>
		mysql<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span> u<span style="color: #66cc66;">,</span>
		mysql<span style="color: #66cc66;">.</span>db d
	<span style="color: #993333; font-weight: bold;">WHERE</span>
		d<span style="color: #66cc66;">.</span>Db <span style="color: #993333; font-weight: bold;">IN</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'db1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'db2'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span>
		d<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span> <span style="color: #66cc66;">=</span> u<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span>
	<span style="color: #993333; font-weight: bold;">UNION</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> u<span style="color: #66cc66;">.*</span>
	<span style="color: #993333; font-weight: bold;">FROM</span>
		mysql<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span> u<span style="color: #66cc66;">,</span>
		mysql<span style="color: #66cc66;">.</span>tables_priv t
	<span style="color: #993333; font-weight: bold;">WHERE</span>
		t<span style="color: #66cc66;">.</span>Db <span style="color: #993333; font-weight: bold;">IN</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'db1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'db2'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span>
		t<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span> <span style="color: #66cc66;">=</span> u<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span>
	<span style="color: #993333; font-weight: bold;">UNION</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> u<span style="color: #66cc66;">.*</span>
	<span style="color: #993333; font-weight: bold;">FROM</span>
		mysql<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span> u<span style="color: #66cc66;">,</span>
		mysql<span style="color: #66cc66;">.</span>procs_priv p
	<span style="color: #993333; font-weight: bold;">WHERE</span>
		p<span style="color: #66cc66;">.</span>Db <span style="color: #993333; font-weight: bold;">IN</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'db1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'db2'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span>
		p<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span> <span style="color: #66cc66;">=</span> u<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- Now, grab the database permissions, and those of objects in the database.</span>
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">OUTFILE</span> <span style="color: #ff0000;">'/tmp/db.txt'</span>
	<span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">','</span> <span style="color: #993333; font-weight: bold;">OPTIONALLY</span> <span style="color: #993333; font-weight: bold;">ENCLOSED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'&quot;'</span> <span style="color: #993333; font-weight: bold;">ESCAPED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>
	<span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
	<span style="color: #993333; font-weight: bold;">FROM</span>
		mysql<span style="color: #66cc66;">.</span>db
	<span style="color: #993333; font-weight: bold;">WHERE</span>
		Db <span style="color: #993333; font-weight: bold;">IN</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'db1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'db2'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span>;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">OUTFILE</span> <span style="color: #ff0000;">'/tmp/tables_priv.txt'</span>
	<span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">','</span> <span style="color: #993333; font-weight: bold;">OPTIONALLY</span> <span style="color: #993333; font-weight: bold;">ENCLOSED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'&quot;'</span> <span style="color: #993333; font-weight: bold;">ESCAPED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>
	<span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
	<span style="color: #993333; font-weight: bold;">FROM</span>
		mysql<span style="color: #66cc66;">.</span>tables_priv
	<span style="color: #993333; font-weight: bold;">WHERE</span>
		Db <span style="color: #993333; font-weight: bold;">IN</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'db1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'db2'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span>;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">OUTFILE</span> <span style="color: #ff0000;">'/tmp/procs_priv.txt'</span>
	<span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">','</span> <span style="color: #993333; font-weight: bold;">OPTIONALLY</span> <span style="color: #993333; font-weight: bold;">ENCLOSED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'&quot;'</span> <span style="color: #993333; font-weight: bold;">ESCAPED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>
	<span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
	<span style="color: #993333; font-weight: bold;">FROM</span>
		mysql<span style="color: #66cc66;">.</span>procs_priv
	<span style="color: #993333; font-weight: bold;">WHERE</span>
		Db <span style="color: #993333; font-weight: bold;">IN</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'db1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'db2'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">...</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div><p>Then, re-loading the permissions onto the new server is simple:</p><div
class="wp_syntax"><div
class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">LOAD</span> <span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #993333; font-weight: bold;">INFILE</span> <span style="color: #ff0000;">'/tmp/user.txt'</span>
	<span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">','</span> <span style="color: #993333; font-weight: bold;">OPTIONALLY</span> <span style="color: #993333; font-weight: bold;">ENCLOSED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'&quot;'</span> <span style="color: #993333; font-weight: bold;">ESCAPED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>
	<span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
	<span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">TABLE</span> mysql<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">USER</span>;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">LOAD</span> <span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #993333; font-weight: bold;">INFILE</span> <span style="color: #ff0000;">'/tmp/db.txt'</span>
	<span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">','</span> <span style="color: #993333; font-weight: bold;">OPTIONALLY</span> <span style="color: #993333; font-weight: bold;">ENCLOSED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'&quot;'</span> <span style="color: #993333; font-weight: bold;">ESCAPED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>
	<span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
	<span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">TABLE</span> mysql<span style="color: #66cc66;">.</span>db;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">LOAD</span> <span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #993333; font-weight: bold;">INFILE</span> <span style="color: #ff0000;">'/tmp/tables_priv.txt'</span>
	<span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">','</span> <span style="color: #993333; font-weight: bold;">OPTIONALLY</span> <span style="color: #993333; font-weight: bold;">ENCLOSED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'&quot;'</span> <span style="color: #993333; font-weight: bold;">ESCAPED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>
	<span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
	<span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">TABLE</span> mysql<span style="color: #66cc66;">.</span>tables_priv;
mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">LOAD</span> <span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #993333; font-weight: bold;">INFILE</span> <span style="color: #ff0000;">'/tmp/procs_priv.txt'</span>
	<span style="color: #993333; font-weight: bold;">FIELDS</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">','</span> <span style="color: #993333; font-weight: bold;">OPTIONALLY</span> <span style="color: #993333; font-weight: bold;">ENCLOSED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'&quot;'</span> <span style="color: #993333; font-weight: bold;">ESCAPED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>
	<span style="color: #993333; font-weight: bold;">LINES</span> <span style="color: #993333; font-weight: bold;">TERMINATED</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
	<span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #993333; font-weight: bold;">TABLE</span> mysql<span style="color: #66cc66;">.</span>procs_priv;</pre></div></div><p>All up, a few queries to account for everything, but pretty easy to include in your backup/restore process. For further development, you could put the database list in a variable, so that you only need to change it on one line, rather than 6.</p> ]]></content:encoded> <wfw:commentRss>http://pento.net/2009/03/12/backing-up-permissions-for-individual-databases/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> </channel> </rss>
