<?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; permissions</title> <atom:link href="http://pento.net/tag/permissions/feed/" rel="self" type="application/rss+xml" /><link>http://pento.net</link> <description>I&#039;m on the Internet</description> <lastBuildDate>Sat, 03 Dec 2011 09:27:46 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <cloud
domain='pento.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' /> <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> <item><title>Permissions by interface on the local server</title><link>http://pento.net/2009/02/19/permissions-by-interface-on-the-local-server/</link> <comments>http://pento.net/2009/02/19/permissions-by-interface-on-the-local-server/#comments</comments> <pubDate>Thu, 19 Feb 2009 07:37:35 +0000</pubDate> <dc:creator>Gary</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[permissions]]></category> <guid
isPermaLink="false">http://pento.net/?p=67</guid> <description><![CDATA[I had an issue come up recently that involved some confusion over permissions for the same user, connecting through different interfaces. For example, say you have a server with the public IP address of 192.168.0.1. You could connect to it from the local machine using the following commands: shell&#62; mysql -h localhost # Connects through [...]]]></description> <content:encoded><![CDATA[<p>I had an issue come up recently that involved some confusion over permissions for the same user, connecting through different interfaces. For example, say you have a server with the public IP address of 192.168.0.1. You could connect to it from the local machine using the following commands:</p><pre>shell&gt; mysql -h localhost           # Connects through the socket file
shell&gt; mysql -h 127.0.0.1           # Connects through the loopback interface
shell&gt; mysql -h 192.168.0.1         # Connects through the network interface</pre><p>They all connect to the local server, but they can all have different permissions. Here are a couple of rules to make your life easier:</p><ul><li>Don&#8217;t use @127.0.0.1, unless you absolutely can&#8217;t use the socket file for some reason. Connecting through @localhost is usually faster than the loopback device, and it&#8217;s easier to type.</li><li>Only connect through the network interface if you&#8217;re planning on moving the application to a different server later on.</li></ul><p>That&#8217;s all. <img
src='http://pento.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> <wfw:commentRss>http://pento.net/2009/02/19/permissions-by-interface-on-the-local-server/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
