<?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>MySQL Preacher &#187; MySQL</title>
	<atom:link href="http://mysqlpreacher.com/wordpress/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://mysqlpreacher.com/wordpress</link>
	<description>A MySQL blog, from a MySQL DBA</description>
	<lastBuildDate>Wed, 16 Jun 2010 13:13:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Automating MySQL access with expect and bash scripting</title>
		<link>http://mysqlpreacher.com/wordpress/2010/02/automating-mysql-access-with-expect-and-bash-scripting/</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/02/automating-mysql-access-with-expect-and-bash-scripting/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 17:08:26 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[expect]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=327</guid>
		<description><![CDATA[If you have multiple database servers with strange names, or if you have to hop over multiple machines to connect to any mysql database server, then you know what a pain it can be to administer such a setup. Thanks to some scripting, you can automate such tasks as follows:
Create an expect script:
/path/to/sshmysql.exp
#!/usr/bin/expect -f
#script by [...]]]></description>
			<content:encoded><![CDATA[<p>If you have multiple database servers with strange names, or if you have to hop over multiple machines to connect to any mysql database server, then you know what a pain it can be to administer such a setup. Thanks to some scripting, you can automate such tasks as follows:</p>
<p>Create an expect script:<br />
/path/to/sshmysql.exp</p>
<blockquote><p>#!/usr/bin/expect -f<br />
#script by darren cassar<br />
#mysqlpreacher.com</p>
<p>set machine  [lindex $argv 0]</p>
<p>set timeout -1</p>
<p>spawn ssh username@$machine<br />
match_max 100000<br />
expect -exact &#8220;assword: &#8221;<br />
send &#8212; &#8220;password\r&#8221;<br />
send &#8212; &#8220;sudo -k; sudo su &#8211; mysql\r&#8221;<br />
expect -exact &#8220;sudo -k; sudo su &#8211; mysql&#8221;<br />
expect -exact &#8220;assword:&#8221;<br />
send &#8212; &#8220;password\r&#8221;<br />
interact</p></blockquote>
<p># you should change the word password in &#8217;send &#8212; &#8220;password\r&#8221;&#8216; to your login password<br />
# if you have the same password for each environment you could also script logging into mysql directly from the same expect script BUT that is not recommended.</p>
<p>Create a bash script:<br />
/path/to/login.sh</p>
<blockquote><p>#!/bin/bash<br />
#script by darren cassar<br />
#mysqlpreacher.com</p>
<p>sm=&#8217;/path/to/sshmysql.exp&#8217;</p>
<p>menu() {<br />
  echo &#8221; 101 &#8211; dev.databaseserver1 &#8221;<br />
  echo &#8221; 102 &#8211; dev.databaseserver2 &#8221;<br />
  echo &#8221; 103 &#8211; dev.databaseserver3 &#8221;<br />
  echo &#8221; 201 &#8211; qa.databaseserver1 &#8221;<br />
  echo &#8221; 301 &#8211; uat.databaseserver1 &#8221;<br />
  echo &#8221; 302 &#8211; uat.databaseserver2 &#8221;<br />
  echo &#8221; 401 &#8211; prod.databaseserver1 &#8221;<br />
  echo &#8221; &#8221;<br />
}</p>
<p>ARGUMENT=notmenu</p>
<p>if [ -z "$1" ]<br />
  then<br />
    ARGUMENT=menu<br />
else<br />
  choice=$1<br />
fi</p>
<p>if [ $ARGUMENT = "menu" ]<br />
  then<br />
    menu<br />
else<br />
  case &#8220;$choice&#8221; in<br />
  101|dev.databaseserver1   ) $sm dev.databaseserver1;;<br />
  102|dev.databaseserver2   ) $sm dev.databaseserver2;;<br />
  103|dev.databaseserver3   ) $sm dev.databaseserver3;;<br />
  201|qa.databaseserver1   ) $sm qa.databaseserver1;;<br />
  301|uat.databaseserver1   ) $sm uat.databaseserver1;;<br />
  302|uat.databaseserver2   ) $sm uat.databaseserver2;;<br />
  401|prod.databaseserver1   ) $sm prod.databaseserver1;;<br />
  *        ) echo &#8220;Wrong value passed to script&#8221;<br />
             menu ;;<br />
  esac<br />
fi</p></blockquote>
<blockquote><p>alias l=&#8217;/path/to/login.sh&#8217;</p></blockquote>
<p>Output: </p>
<blockquote><p>[darrencassar@mymachine ~ ]$ l<br />
 101 &#8211; dev.databaseserver1<br />
 102 &#8211; dev.databaseserver2<br />
 103 &#8211; dev.databaseserver3<br />
 201 &#8211; qa.databaseserver1<br />
 301 &#8211; uat.databaseserver1<br />
 302 &#8211; uat.databaseserver2<br />
 401 &#8211; prod.databaseserver1</p></blockquote>
<p>Output:<br />
The below command would log you into the first development database server as mysql user.</p>
<blockquote><p>[darrencassar@mymachine ~ ]$ l 101 </p></blockquote>
<p>On each machine place aliases for each instance in the .profile</p>
<blockquote><p>alias use3306=&#8217;mysql -u root -p -h 127.0.0.1 -P 3306 &#8211;prompt=&#8221;mysql \D> &#8220;&#8216;</p></blockquote>
<p>The above setup can be used using any client/server OS: Linux, Solaris, MAC OS or Windows(running Cygwin)</p>
<p><strong>NOTE: If you store the password in clear text inside the expect script, you should at least save the scripts inside an encrypted partition on your machine and make sure that folder is not shared or accessible by anyone. Another way of doing it would be to use either SSHKeys OR save the password inside a file and encrypt it using <a href="http://www.madboa.com/geek/openssl/#encrypt-simple" target="_blank">OpenSSL</a></strong></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2010/02/automating-mysql-access-with-expect-and-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL vs InfoBright optimizer battle</title>
		<link>http://mysqlpreacher.com/wordpress/2009/12/mysql-vs-infobright-optimizer-battle/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/12/mysql-vs-infobright-optimizer-battle/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 17:33:36 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[infobright]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[optimiser]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=302</guid>
		<description><![CDATA[MySQL instance running an Infobright engine

mysql> explain SELECT COUNT(ac.UID) FROM ACTIVE ac JOIN ALL a;
+----+-------------+-------+------+---------------+------+---------+------+---------+-------+
&#124; id &#124; select_type &#124; table &#124; type &#124; possible_keys &#124; key  &#124; key_len &#124; ref  &#124; rows    &#124; Extra &#124;
+----+-------------+-------+------+---------------+------+---------+------+---------+-------+
&#124;  1 &#124; SIMPLE      &#124; ac    &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL instance running an Infobright engine</p>
<blockquote><p><code lang="sql"><br />
mysql> explain SELECT COUNT(ac.UID) FROM ACTIVE ac JOIN ALL a;<br />
+----+-------------+-------+------+---------------+------+---------+------+---------+-------+<br />
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows    | Extra |<br />
+----+-------------+-------+------+---------------+------+---------+------+---------+-------+<br />
|  1 | SIMPLE      | ac    | ALL  | NULL          | NULL | NULL    | NULL |  124426 |       |<br />
|  1 | SIMPLE      | a     | ALL  | NULL          | NULL | NULL    | NULL | 7594256 |       |<br />
+----+-------------+-------+------+---------------+------+---------+------+---------+-------+<br />
2 rows in set (0.01 sec)</p>
<p>mysql> SELECT COUNT(ac.UID) FROM ACTIVE ac JOIN ALL a ON ac.UID=a.UID;<br />
+---------------+<br />
| COUNT(ac.UID) |<br />
+---------------+<br />
|         17466 |<br />
+---------------+<br />
1 row in set (0.23 sec)</p>
<p>mysql> set @tot = (SELECT COUNT(ac.UID) FROM ACTIVE ac JOIN ALL a ON ac.UID=a.UID); </p>
<p>^CQuery aborted by Ctrl+C<br />
</code></p></blockquote>
<p>Took more than 60seconds &#8212;- what the &#8230;..<br />
Why did it take a long?</p>
<blockquote><p><code lang="sql"><br />
mysql> set @a=2;<br />
Query OK, 0 rows affected (0.00 sec)</p>
<p>mysql> select @a;<br />
+------+<br />
| @a   |<br />
+------+<br />
| 2    |<br />
+------+<br />
1 row in set (0.00 sec)</p>
<p>mysql> set @tot = (SELECT COUNT(*) FROM ACTIVE);<br />
Query OK, 0 rows affected (0.13 sec)</p>
<p>mysql> select @tot;<br />
+--------+<br />
| @tot   |<br />
+--------+<br />
| 124426 |<br />
+--------+<br />
1 row in set (0.00 sec)</p>
<p>mysql> set @tot = (SELECT COUNT(ac.UID) FROM ACTIVE ac);<br />
Query OK, 0 rows affected (0.22 sec)</p>
<p>mysql> select @tot;<br />
+--------+<br />
| @tot   |<br />
+--------+<br />
| 124426 |<br />
+--------+<br />
1 row in set (0.00 sec)</p>
<p>mysql> SELECT COUNT(ac.UID) FROM ACTIVE ac, ALL a;<br />
+---------------+<br />
| COUNT(ac.UID) |<br />
+---------------+<br />
|  944922897056 |<br />
+---------------+<br />
1 row in set (0.05 sec)</p>
<p>mysql> set @tot=(SELECT COUNT(ac.UID) FROM ACTIVE ac JOIN ALL a);<br />
^CQuery aborted by Ctrl+C<br />
ERROR 1317 (70100): Query execution was interrupted<br />
</code></p></blockquote>
<p>Reason? &#8230;. the query is using the MySQL optimiser rather than the IB one! Why? good question (will have to ask IB devs though).</p>
<p>Work around, use ac temporary table to store the result and setting the variable to the result field, but it&#8217;s really ugly isn&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/12/mysql-vs-infobright-optimizer-battle/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL related bookmark collection</title>
		<link>http://mysqlpreacher.com/wordpress/2009/09/mysql-related-bookmark-collection/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/09/mysql-related-bookmark-collection/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 10:40:27 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[benchmarking]]></category>
		<category><![CDATA[bookmarks]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[general knowledge]]></category>
		<category><![CDATA[ha]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[performance analysis]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[slow queries]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=293</guid>
		<description><![CDATA[I am publishing my MySQL related bookmark collection http://www.mysqlpreacher.com/bookmarks/.
Feel free to send me links you think might be good to add in order to help others.
Remember, SHARING IS CARING!!! …. we get so much for free, why shouldn’t we give some back?
Cheers,
Darren
]]></description>
			<content:encoded><![CDATA[<p>I am publishing my MySQL related bookmark collection <strong><a href="http://www.mysqlpreacher.com/bookmarks/" target="_blank">http://www.mysqlpreacher.com/bookmarks/</a></strong>.</p>
<p>Feel free to send me links you think might be good to add in order to help others.</p>
<p>Remember, SHARING IS CARING!!! …. we get so much for free, why shouldn’t we give some back?</p>
<p>Cheers,<br />
Darren</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/09/mysql-related-bookmark-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securich &#8211; The MySQL Security Package step by step run through</title>
		<link>http://mysqlpreacher.com/wordpress/2009/06/securich-the-mysql-security-package-step-by-step-run-through/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/06/securich-the-mysql-security-package-step-by-step-run-through/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 17:02:47 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mysql roles]]></category>
		<category><![CDATA[mysql security]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[password history]]></category>
		<category><![CDATA[privileges]]></category>
		<category><![CDATA[roles]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=195</guid>
		<description><![CDATA[I would like to start off by excusing myself for having had a broken link on <a href="http://www.securich.com/downloads.html">http://www.securich.com/downloads.html</a> when I published the latest blog post about Securich.

The tool is downloadable from there and anyone can use it for free in accordance to GPLv2.

I wanted to throw out tutorial about how to install it and use it (Note this tutorial is for version securich version 0.1.2):]]></description>
			<content:encoded><![CDATA[<p>I would like to start off by excusing myself for having had a broken link on <a href="http://www.securich.com/downloads.html">http://www.securich.com/downloads.html</a> when I published the latest blog post about Securich.</p>
<p>The tool is downloadable from there and anyone can use it for free in accordance to GPLv2.</p>
<p>I wanted to throw out tutorial about how to install it and use it (Note this tutorial is for version securich version 0.1.2):</p>
<p>Steps:<br />
1. Download it,<br />
2. Install it,<br />
3. Create a role named &#39;role1&#39; having privileges: select insert update<br />
4. Check roles,<br />
5. Check role privileges,<br />
6. Create a first user<em> john@machine.domain.com</em> (granting privileges on a whole database employees apart from one table),<br />
7. Create a second user<em> paul@10.0.0.2</em> (granting privileges on all tables in world having word Country in them),<br />
8. Create a third user <em>peter@localhost</em> (granting privileges on the database test),<br />
9. Check user privileges for (<em>paul</em>),<br />
10. Update role created above and see changes (add delete to role 1),<br />
11. Update password (for <em>paul</em>) and see changes,<br />
12. Clone user <em>paul</em> to <em>judas</em>,<br />
13. Check user privileges<br />
14. Check user,<br />
15. Rename user <em>judas</em> to <em>james</em>,<br />
16. Revoke privileges from third user disconnecting any existing connections from that user (useful if a security breach is suspected or if you are a security paranoid thus wanting to make sure the person you are blocking out won&#39;t have any more access as from that point onwards).</p>
<p>1. Go to www.securich.com downloads page and download the install script<br />
2. Untar the install script and run it using ./securich_install.sh and it&#39;ll install everything automatically</p>
<blockquote><p>      dcassar@ubuntu:~/Desktop$ ./securich_install.sh<br />
      Enter version number: 0.1.1<br />
      Which kind of installation would you like to do?<br />
      1. Install from file on disk<br />
      2. Download and install (recommended)<br />
      Enter choice (default 2):</p>
<p>      Installation starting<br />
      &#8211;2009-06-19 16:27:56&#8211;  http://www.securich.com/downloads/securich.0.1.1.tar.gz<br />
      Resolving www.securich.com&#8230; 64.202.163.10<br />
      Connecting to www.securich.com|64.202.163.10|:80&#8230; connected.<br />
      HTTP request sent, awaiting response&#8230; 200 OK<br />
      Length: 29217 (29K) [application/x-tar]<br />
      Saving to: `securich.0.1.1.tar.gz&#39;</p>
<p>      100%[=====================================================================================================>] 29,217      64.7K/s   in 0.4s</p>
<p>      2009-06-19 16:27:59	(64.7 KB/s) &#8211; &#39;securich.0.1.1.tar.gz&#39; saved [29217/29217]</p>
<p>      Enter mysql root Password (default ):<br />
      Enter mysql Hostname/IP (default 127.0.0.1): localhost<br />
      Enter mysql Port (default 3306): 3306<br />
      Installation complete</p></blockquote>
<p>3. #log into mysql<br />
   use securich;<br />
   call create_update_role(&#39;role1&#39;,&#39;select&#39;);<br />
   call create_update_role(&#39;role1&#39;,&#39;insert&#39;);<br />
   call create_update_role(&#39;role1&#39;,&#39;update&#39;);<br />
4. call check_roles();<br />
5. call check_role_privileges(&#39;role1&#39;);<br />
6. call grant_privileges(&#39;john&#39; , &#39;machine.domain.com&#39; , &#39;employees&#39; , &#39;&#39; , &#39;alltables&#39; , &#39;role1&#39; , &#39;john@domain.com&#39;);<br />
   call revoke_privileges(&#39;john&#39; , &#39;machine.domain.com&#39; , &#39;employees&#39; , &#39;salaries&#39; , &#39;table&#39; , &#39;role1&#39; , &#39;N&#39;);<br />
7. call grant_privileges(&#39;paul&#39; , &#39;10.0.0.2&#39; , &#39;world&#39; , &#39;^Country&#39; , &#39;regexp&#39; , &#39;role1&#39; , &#39;paul@domain.com&#39;);<br />
8. call grant_privileges(&#39;peter&#39; , &#39;localhost&#39; , &#39;test&#39; , &#39;&#39; , &#39;all&#39; , &#39;role1&#39; , &#39;peter@domain.com&#39;);<br />
9. call check_full_user_entries(&#39;paul&#39;);<br />
10. call create_update_role(&#39;role1&#39;,&#39;delete&#39;);<br />
    call check_full_user_entries(&#39;paul&#39;);<br />
11. call set_password(&#39;paul&#39; , &#39;10.0.0.2&#39; , &#39;password123&#39;);<br />
12. call clone_user(&#39;paul&#39; , &#39;10.0.0.2&#39; , &#39;judas&#39; , &#39;10.0.0.2&#39; , &#39;judas@domain.com&#39;);<br />
13. call check_full_user_entries(&#39;judas&#39;);<br />
14. call check_user_privileges(&#39;judas&#39; , &#39;10.0.0.2&#39; , &#39;world&#39; , &#39;role1&#39;);<br />
15. call rename_user(&#39;judas&#39; , &#39;james&#39; , &#39;james@domain.com&#39;);<br />
16. call create_update_role(&#39;role2&#39;,&#39;execute&#39;);<br />
17. call grant_privileges(&#39;peter&#39; , &#39;localhost&#39; , &#39;securich&#39; , &#39;my_privileges&#39; , &#39;storedprocedure&#39; , &#39;role2&#39; , &#39;peter@domain.com&#39;);</p>
<p>18. #connect to mysql using thirduser peter in another session<br />
    show databases;<br />
    use securich;<br />
    show tables;<br />
    call my_privileges(&#39;test&#39;);<br />
    show processlist;</p>
<p>19. call revoke_privileges(&#39;peter&#39; , &#39;localhost&#39; , &#39;test&#39; , &#39;&#39; , &#39;&#39; , &#39;role1&#39; , &#39;Y&#39;);</p>
<p>20. #as user peter again from 2nd open instance run<br />
    show processlist;</p>
<blockquote><p>dcassar@ubuntu:~/Desktop$ ./securich_install.sh<br />
Enter version number: 0.1.1<br />
Which kind of installation would you like to do?<br />
1. Install from file on disk<br />
2. Download and install (recommended)<br />
Enter choice (default 2): </p>
<p>Installation starting<br />
&#8211;2009-06-19 16:27:56&#8211;  http://www.securich.com/downloads/securich.0.1.1.tar.gz<br />
Resolving www.securich.com&#8230; 64.202.163.10<br />
Connecting to www.securich.com|64.202.163.10|:80&#8230; connected.<br />
HTTP request sent, awaiting response&#8230; 200 OK<br />
Length: 29217 (29K) [application/x-tar]<br />
Saving to: `securich.0.1.1.tar.gz&#39;</p>
<p>100%[=====================================================================================================>] 29,217      64.7K/s   in 0.4s    </p>
<p>2009-06-19 16:27:59 (64.7 KB/s) &#8211; `securich.0.1.1.tar.gz&#39; saved [29217/29217]</p>
<p>Enter mysql root Password (default ):<br />
Enter mysql Hostname/IP (default 127.0.0.1): localhost<br />
Enter mysql Port (default 3306): 3306<br />
Installation complete<br />
dcassar@ubuntu:~/Desktop$ mysql -u root -p -h 127.0.0.1 -P 3306 Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 429<br />
Server version: 5.1.33 MySQL Community Server (GPL)</p>
<p>Type &#39;help;&#39; or &#39;\h&#39; for help. Type &#39;\c&#39; to clear the buffer.</p>
<p>mysql> use securich;<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A</p>
<p>Database changed<br />
mysql> call create_update_role(&#39;role1&#39;,&#39;select&#39;);<br />
Query OK, 0 rows affected, 5 warnings (0.03 sec)</p>
<p>mysql> call create_update_role(&#39;role1&#39;,&#39;insert&#39;);<br />
Query OK, 0 rows affected (0.04 sec)</p>
<p>mysql> call create_update_role(&#39;role1&#39;,&#39;update&#39;);<br />
Query OK, 0 rows affected (0.04 sec)</p>
<p>mysql> call check_roles();<br />
+&#8212;-+&#8212;&#8212;-+<br />
| ID | ROLE  |<br />
+&#8212;-+&#8212;&#8212;-+<br />
|  1 | read  |<br />
|  2 | write |<br />
|  3 | role1 |<br />
+&#8212;-+&#8212;&#8212;-+<br />
3 rows in set (0.00 sec)</p>
<p>Query OK, 0 rows affected (0.00 sec)</p>
<p>mysql> call check_role_privileges(&#39;role1&#39;);<br />
+&#8212;&#8212;&#8212;&#8211;+<br />
| PRIVILEGE |<br />
+&#8212;&#8212;&#8212;&#8211;+<br />
| INSERT    |<br />
| SELECT    |<br />
| UPDATE    |<br />
+&#8212;&#8212;&#8212;&#8211;+<br />
3 rows in set (0.00 sec)</p>
<p>Query OK, 0 rows affected (0.00 sec)</p>
<p>mysql> call grant_privileges(&#39;john&#39; , &#39;machine.domain.com&#39; , &#39;employees&#39; , &#39;&#39; , &#39;alltables&#39; , &#39;role1&#39; , &#39;john@domain.com&#39;);<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| USER_PASSWORD                                                                              |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| Password for user &#8212; john &#8212; contactable at &#8212; john@domain.com &#8212; is &#8212; bfcbd8234d9eb44 &#8212; |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
1 row in set (0.16 sec)</p>
<p>Query OK, 0 rows affected, 1 warning (0.16 sec)</p>
<p>mysql> call revoke_privileges(&#39;john&#39; , &#39;machine.domain.com&#39; , &#39;employees&#39; , &#39;salaries&#39; , &#39;table&#39; , &#39;role1&#39; , &#39;N&#39;);<br />
Query OK, 0 rows affected (0.09 sec)</p>
<p>mysql> call grant_privileges(&#39;paul&#39; , &#39;10.0.0.2&#39; , &#39;world&#39; , &#39;^Country&#39; , &#39;regexp&#39; , &#39;role1&#39; , &#39;paul@domain.com&#39;);<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| USER_PASSWORD                                                                              |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| Password for user &#8212; paul &#8212; contactable at &#8212; paul@domain.com &#8212; is &#8212; bc4ab08785e1be6 &#8212; |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
1 row in set (0.06 sec)</p>
<p>Query OK, 0 rows affected, 1 warning (0.06 sec)</p>
<p>mysql> call grant_privileges(&#39;peter&#39; , &#39;localhost&#39; , &#39;test&#39; , &#39;&#39; , &#39;all&#39; , &#39;role1&#39; , &#39;peter@domain.com&#39;);<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| USER_PASSWORD                                                                             |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| Password for user &#8212; peter &#8212; contactable at &#8212; peter@domain.com &#8212; is &#8212; 7b3b4746d04b &#8212; |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
1 row in set (0.04 sec)</p>
<p>Query OK, 0 rows affected (0.04 sec)</p>
<p>mysql> call check_full_user_entries(&#39;paul&#39;);<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br />
| USERNAME | HOSTNAME | DATABASENAME | TABLENAME       | ROLE  | PRIVILEGE | STATE |<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br />
| paul     | 10.0.0.2 | world        | Country         | role1 | INSERT    | A     |<br />
| paul     | 10.0.0.2 | world        | Country         | role1 | SELECT    | A     |<br />
| paul     | 10.0.0.2 | world        | Country         | role1 | UPDATE    | A     |<br />
| paul     | 10.0.0.2 | world        | CountryLanguage | role1 | INSERT    | A     |<br />
| paul     | 10.0.0.2 | world        | CountryLanguage | role1 | SELECT    | A     |<br />
| paul     | 10.0.0.2 | world        | CountryLanguage | role1 | UPDATE    | A     |<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br />
6 rows in set (0.01 sec)</p>
<p>Query OK, 0 rows affected, 4 warnings (0.01 sec)</p>
<p>mysql> call create_update_role(&#39;role1&#39;,&#39;delete&#39;);<br />
Query OK, 0 rows affected (0.09 sec)</p>
<p>mysql> call check_full_user_entries(&#39;paul&#39;);<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br />
| USERNAME | HOSTNAME | DATABASENAME | TABLENAME       | ROLE  | PRIVILEGE | STATE |<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br />
| paul     | 10.0.0.2 | world        | Country         | role1 | DELETE    | A     |<br />
| paul     | 10.0.0.2 | world        | Country         | role1 | INSERT    | A     |<br />
| paul     | 10.0.0.2 | world        | Country         | role1 | SELECT    | A     |<br />
| paul     | 10.0.0.2 | world        | Country         | role1 | UPDATE    | A     |<br />
| paul     | 10.0.0.2 | world        | CountryLanguage | role1 | DELETE    | A     |<br />
| paul     | 10.0.0.2 | world        | CountryLanguage | role1 | INSERT    | A     |<br />
| paul     | 10.0.0.2 | world        | CountryLanguage | role1 | SELECT    | A     |<br />
| paul     | 10.0.0.2 | world        | CountryLanguage | role1 | UPDATE    | A     |<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br />
8 rows in set (0.00 sec)</p>
<p>Query OK, 0 rows affected (0.00 sec)</p>
<p>mysql> call set_password(&#39;paul&#39; , &#39;10.0.0.2&#39; , &#39;password123&#39;);<br />
Query OK, 1 row affected (0.02 sec)</p>
<p>mysql> call clone_user(&#39;paul&#39; , &#39;10.0.0.2&#39; , &#39;judas&#39; , &#39;10.0.0.2&#39; , &#39;judas@domain.com&#39;);<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| USER_PASSWORD                                                                                |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| Password for user &#8212; judas &#8212; contactable at &#8212; judas@domain.com &#8212; is &#8212; 70d5b79d80fab04 &#8212; |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
1 row in set (0.01 sec)</p>
<p>Query OK, 0 rows affected, 1 warning (0.10 sec)</p>
<p>mysql> call check_full_user_entries(&#39;judas&#39;);<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br />
| USERNAME | HOSTNAME | DATABASENAME | TABLENAME       | ROLE  | PRIVILEGE | STATE |<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br />
| judas    | 10.0.0.2 | world        | Country         | role1 | DELETE    | A     |<br />
| judas    | 10.0.0.2 | world        | Country         | role1 | INSERT    | A     |<br />
| judas    | 10.0.0.2 | world        | Country         | role1 | SELECT    | A     |<br />
| judas    | 10.0.0.2 | world        | Country         | role1 | UPDATE    | A     |<br />
| judas    | 10.0.0.2 | world        | CountryLanguage | role1 | DELETE    | A     |<br />
| judas    | 10.0.0.2 | world        | CountryLanguage | role1 | INSERT    | A     |<br />
| judas    | 10.0.0.2 | world        | CountryLanguage | role1 | SELECT    | A     |<br />
| judas    | 10.0.0.2 | world        | CountryLanguage | role1 | UPDATE    | A     |<br />
+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br />
8 rows in set (0.00 sec)</p>
<p>Query OK, 0 rows affected (0.00 sec)</p>
<p>mysql> call check_user_privileges(&#39;judas&#39; , &#39;10.0.0.2&#39; , &#39;world&#39; , &#39;role1&#39;);<br />
+&#8212;&#8212;&#8212;&#8211;+<br />
| PRIVILEGE |<br />
+&#8212;&#8212;&#8212;&#8211;+<br />
| DELETE    |<br />
| INSERT    |<br />
| SELECT    |<br />
| UPDATE    |<br />
+&#8212;&#8212;&#8212;&#8211;+<br />
4 rows in set (0.00 sec)</p>
<p>Query OK, 0 rows affected (0.00 sec)</p>
<p>mysql> call rename_user(&#39;judas&#39; , &#39;james&#39; , &#39;james@domain.com&#39;);<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| USER_PASSWORD                                                                                |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| Password for user &#8212; james &#8212; contactable at &#8212; james@domain.com &#8212; is &#8212; 85c2fc100d83884 &#8212; |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
1 row in set (0.02 sec)</p>
<p>Query OK, 0 rows affected, 1 warning (0.11 sec)</p>
<p>mysql> call create_update_role(&#39;role2&#39;,&#39;execute&#39;);<br />
Query OK, 0 rows affected (0.09 sec)</p>
<p>mysql> call grant_privileges(&#39;peter&#39; , &#39;localhost&#39; , &#39;securich&#39; , &#39;my_privileges&#39; , &#39;storedprocedure&#39; , &#39;role2&#39; , &#39;peter@domain.com&#39;);<br />
Query OK, 0 rows affected (0.08 sec)</p>
<p>mysql> call revoke_privileges(&#39;peter&#39; , &#39;localhost&#39; , &#39;test&#39; , &#39;&#39; , &#39;&#39; , &#39;role1&#39; , &#39;Y&#39;);<br />
Query OK, 0 rows affected (0.15 sec)</p>
<p>mysql> </p>
<p>dcassar@ubuntu:~/Desktop$ mysql -u peter -p7b3b4746d04b -h 127.0.0.1 -P 3306<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 437<br />
Server version: 5.1.33 MySQL Community Server (GPL)</p>
<p>Type &#39;help;&#39; or &#39;\h&#39; for help. Type &#39;\c&#39; to clear the buffer.</p>
<p>mysql> show processlist;<br />
+&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| Id  | User  | Host            | db   | Command | Time | State | Info             |<br />
+&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| 437 | peter | localhost:49022 | NULL | Query   |    0 | NULL  | show processlist |<br />
+&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
1 row in set (0.00 sec)</p>
<p>mysql> show databases;<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| Database           |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| information_schema |<br />
| securich           |<br />
| test               |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
3 rows in set (0.00 sec)</p>
<p>mysql> use securich;<br />
Database changed<br />
mysql> show tables;<br />
Empty set (0.00 sec)</p>
<p>**** Note that the only privileges peter has on securich is on the stored procedure &#39;my_privileges&#39; and definitely no tables</p>
<p>mysql> call my_privileges(&#39;test&#39;);<br />
+&#8212;&#8212;&#8212;&#8211;+<br />
| PRIVILEGE |<br />
+&#8212;&#8212;&#8212;&#8211;+<br />
| DELETE    |<br />
| INSERT    |<br />
| SELECT    |<br />
| UPDATE    |<br />
+&#8212;&#8212;&#8212;&#8211;+<br />
4 rows in set (0.00 sec)</p>
<p>Query OK, 0 rows affected (0.00 sec)</p>
<p>mysql> show processlist;<br />
+&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| Id  | User  | Host            | db   | Command | Time | State | Info             |<br />
+&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
| 437 | peter | localhost:49022 | NULL | Query   |    0 | NULL  | show processlist |<br />
+&#8212;&#8211;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;+&#8212;&#8212;&#8212;+&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br />
1 row in set (0.00 sec)</p>
<p>****** &#8211; In the meantime the dba revoked rights with terminate live connections from peter@localhost</p>
<p>mysql> show processlist;<br />
ERROR 2006 (HY000): MySQL server has gone away<br />
No connection. Trying to reconnect&#8230;<br />
ERROR 1045 (28000): Access denied for user &#39;peter&#39;@&#39;localhost&#39; (using password: YES)<br />
ERROR:<br />
Can&#39;t connect to the server</p>
<p>mysql> </p>
</blockquote>
<p>I truly hope you enjoyed this run through. I excuse myself it&#39;s a tad too long, but I wished to illustrate some of the cool features of this package.</p>
<p>Cheers,<br />
Darren</p>
<p>PS don&#39;t forget to check out <a href="http://www.securich.com">Securich HERE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/06/securich-the-mysql-security-package-step-by-step-run-through/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security &#8211; Roles and Password Expiry on MySQL using SECURICH</title>
		<link>http://mysqlpreacher.com/wordpress/2009/06/security-roles-and-password-expiry-on-mysql-using-securich/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/06/security-roles-and-password-expiry-on-mysql-using-securich/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 09:23:56 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[groups]]></category>
		<category><![CDATA[password expiry]]></category>
		<category><![CDATA[password history]]></category>
		<category><![CDATA[roles]]></category>
		<category><![CDATA[securich]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=182</guid>
		<description><![CDATA[Lately there has been quite some talk about security on MySQL, and I've decided to GPL a package I wrote, implmenting Roles on MySQL.
This technology has been available on other databases for quite some time, but hasn't quite yet made it to MySQL's feature list and apart from this tool, the only solution I know of is google's patches for MySQL 5.0.
]]></description>
			<content:encoded><![CDATA[<p>Lately there has been quite some talk about security on MySQL, and I&#8217;ve decided to GPL a package I wrote, implmenting Roles on MySQL.<br />
This technology has been available on other databases for quite some time, but hasn&#8217;t quite yet made it to MySQL&#8217;s feature list and apart from this tool, the only solution I know of is google&#8217;s patches for MySQL 5.0.</p>
<p>The name is SECURICH and downloads as well as documentation are available at <a href="http://www.securich.com/">http://www.securich.com/</a>. The bug list is available at <a href="http://www.securich.com/mantis/">http://www.securich.com/mantis/</a> (you&#8217;ll have to register and log in first). Privileges can be granted on a database or table level with a few combinations like:<br />
	1. database as one,<br />
	2. all tables in database (useful when you need to grant a bunch of privileges to all tables but a few thus revoking the few later),<br />
	3. single tables,<br />
	4. stored procedure or<br />
	5. tables through the use of regular expression.</p>
<p>The user has the facility to create a role and update it on the fly thus propagating the changes onto already existing users having the role in question. There are also loads of other functionalities available and I urge you to check the documentation on <a href="http://www.securich.com/">http://www.securich.com/</a>.</p>
<p>A cool feature I like is password history which enables dbas to enforce changing of passwords after a certain period of time. </p>
<p>#################################################################################################################################################<br />
## PLEASE NOTE THAT:<br />
## 1. THIS IS AN ALPHA VERSION,<br />
## 2. YOU SHOULD NOT INSTALL THIS PACKAGE ON A PRE-EXISTING MYSQL WHICH ALREADY HAS PRIVILEGES SET UP.<br />
#################################################################################################################################################<br />
##<br />
## This tool will modify current privileges on the &#8220;mysql&#8221; database tables and should only be used with freshly installed mysqls.<br />
##<br />
##################################################################################################################################################</p>
<p>Features like block user and unblock user as well as many other functionalities are being developed and more features will be added as time goes by.</p>
<p>I would greatly appreciate your feedback about what you think of the package, features you might wish to include etc (feature requests should be done through <a href="http://www.securich.com/mantis/">http://www.securich.com/mantis/</a> as well.)</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/06/security-roles-and-password-expiry-on-mysql-using-securich/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replicating from MySQL to *</title>
		<link>http://mysqlpreacher.com/wordpress/2009/05/replicating-from-mysql-to/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/05/replicating-from-mysql-to/#comments</comments>
		<pubDate>Fri, 29 May 2009 16:28:28 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mysqlbinlog]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[row based replication]]></category>
		<category><![CDATA[statement based replication]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=175</guid>
		<description><![CDATA[Recently I needed to replicate between MySQL and another database technology. You might say, why on earth would you want to do something like that, but believe me there are reasons and definitely not (to go away from MySQL to some other DB technology like Oracle or SQL server). Unsurprisingly there are quite a few different tools to do it from any platform towards MySQL but very few which do it the other way round, just to name a couple: Golden Gate and DSCallards.]]></description>
			<content:encoded><![CDATA[<p><strong>Obtaining ansi SQL from RBR.</strong></p>
<p>Recently I needed to replicate between MySQL and another database technology. You might say, why on earth would you want to do something like that, but believe me there are reasons and definitely not (to go away from MySQL to some other DB technology like Oracle or SQL server). Unsurprisingly there are quite a few different tools to do it from any platform towards MySQL but very few which do it the other way round, just to name a couple: Golden Gate and DSCallards.</p>
<p>Whilst not going into their tools (you can find more information on their websites), HIT from DSCallards needs its software to run on Windows and Golden Gate is an expensive beast which was too much for what I needed, thus I decided to have a look at doing the job myself. Although it might look an overkill to do so, it took me a few hours to find a solution and implement it and a couple more to test it and here is a simple description.</p>
<p>MySQL replication can be SBR (statement based), RBR (row based) or a mixture of both. Now despite the fact that the mixture provides the best performance, it would be the most complicated in order to achieve a home made solution, and SBR in my opinion would have also been a bit of a headache to make sure queries didn&#8217;t contain non ansi sql through the use of functions like now(), sysdate() and many others. I therefore decided that RBR would be the option of choice.</p>
<p>Although I wonder how many of you ever read an RBR binlog using `mysqlbinlog mysql-bin.000004`, it would be something like:</p>
<blockquote><p>
#090526 14:09:13 server id 1  end_log_pos 1420  Query   thread_id=192   exec_time=0     error_code=0<br />
SET TIMESTAMP=1243343353/*!*/;<br />
BEGIN<br />
/*!*/;<br />
# at 1420<br />
# at 1464<br />
#090526 14:09:13 server id 1  end_log_pos 1464  Table_map: `test`.`t2` mapped to number 21<br />
#090526 14:09:13 server id 1  end_log_pos 1498  Write_rows: table id 21 flags: STMT_END_F</p>
<p>BINLOG &#8216;<br />
+ekbShMBAAAALAAAALgFAAAAABUAAAAAAAAABHRlc3QAAnQyAAID/gL+AQM=<br />
+ekbShcBAAAAIgAAANoFAAAQABUAAAAAAAEAAv/+AQAAAA==<br />
&#8216;/*!*/;<br />
# at 1498<br />
#090526 14:09:13 server id 1  end_log_pos 1567  Query   thread_id=192   exec_time=0     error_code=0<br />
SET TIMESTAMP=1243343353/*!*/;<br />
COMMIT<br />
/*!*/;<br />
# at 1567<br />
#090526 14:09:38 server id 1  end_log_pos 1635  Query   thread_id=192   exec_time=0     error_code=0<br />
SET TIMESTAMP=1243343378/*!*/;<br />
BEGIN<br />
/*!*/;<br />
# at 1635<br />
# at 1679<br />
#090526 14:09:38 server id 1  end_log_pos 1679  Table_map: `test`.`t2` mapped to number 21<br />
#090526 14:09:38 server id 1  end_log_pos 1733  Update_rows: table id 21 flags: STMT_END_F</p>
<p>BINLOG &#8216;<br />
EuobShMBAAAALAAAAI8GAAAAABUAAAAAAAAABHRlc3QAAnQyAAID/gL+AQM=<br />
EuobShgBAAAANgAAAMUGAAAQABUAAAAAAAEAAv///AQAAAABZPwCAAAAAWT+AQAAAP4CAAAA<br />
&#8216;/*!*/;<br />
# at 1733<br />
#090526 14:09:38 server id 1  end_log_pos 1802  Query   thread_id=192   exec_time=0     error_code=0<br />
SET TIMESTAMP=1243343378/*!*/;<br />
COMMIT
</p></blockquote>
<p>Now that isn&#8217;t the most readable text you ever seen right? As Giuseppe said &#8220;This is more difficult to read than ancient Etruscan. If you are a DBA, you curse and look for help.&#8221; But the replication guys at mysql created a nice -v for us to add to mysqlbinlog thus issuing `mysqlbinlog -v mysql-bin.000004` would result in the following:</p>
<blockquote><p>
#090526 14:09:13 server id 1  end_log_pos 1420  Query   thread_id=192   exec_time=0     error_code=0<br />
SET TIMESTAMP=1243343353/*!*/;<br />
BEGIN<br />
/*!*/;<br />
# at 1420<br />
# at 1464<br />
#090526 14:09:13 server id 1  end_log_pos 1464  Table_map: `test`.`t2` mapped to number 21<br />
#090526 14:09:13 server id 1  end_log_pos 1498  Write_rows: table id 21 flags: STMT_END_F</p>
<p>BINLOG &#8216;<br />
+ekbShMBAAAALAAAALgFAAAAABUAAAAAAAAABHRlc3QAAnQyAAID/gL+AQM=<br />
+ekbShcBAAAAIgAAANoFAAAQABUAAAAAAAEAAv/+AQAAAA==<br />
&#8216;/*!*/;<br />
### INSERT INTO test.t2<br />
### SET<br />
###   @1=1<br />
###   @2=NULL<br />
# at 1498<br />
#090526 14:09:13 server id 1  end_log_pos 1567  Query   thread_id=192   exec_time=0     error_code=0<br />
SET TIMESTAMP=1243343353/*!*/;<br />
COMMIT<br />
/*!*/;<br />
# at 1567<br />
#090526 14:09:38 server id 1  end_log_pos 1635  Query   thread_id=192   exec_time=0     error_code=0<br />
SET TIMESTAMP=1243343378/*!*/;<br />
BEGIN<br />
/*!*/;<br />
# at 1635<br />
# at 1679<br />
#090526 14:09:38 server id 1  end_log_pos 1679  Table_map: `test`.`t2` mapped to number 21<br />
#090526 14:09:38 server id 1  end_log_pos 1733  Update_rows: table id 21 flags: STMT_END_F</p>
<p>BINLOG &#8216;<br />
EuobShMBAAAALAAAAI8GAAAAABUAAAAAAAAABHRlc3QAAnQyAAID/gL+AQM=<br />
EuobShgBAAAANgAAAMUGAAAQABUAAAAAAAEAAv///AQAAAABZPwCAAAAAWT+AQAAAP4CAAAA<br />
&#8216;/*!*/;<br />
### UPDATE test.t2<br />
### WHERE<br />
###   @1=4<br />
###   @2=&#8217;d&#8217;<br />
### SET<br />
###   @1=2<br />
###   @2=&#8217;d&#8217;<br />
### UPDATE test.t2<br />
### WHERE<br />
###   @1=1<br />
###   @2=NULL<br />
### SET<br />
###   @1=2<br />
###   @2=NULL<br />
# at 1733<br />
#090526 14:09:38 server id 1  end_log_pos 1802  Query   thread_id=192   exec_time=0     error_code=0<br />
SET TIMESTAMP=1243343378/*!*/;<br />
COMMIT
</p></blockquote>
<p>The exact same output with some decently readable output. The problem at this point is that the output is not really something any other technology would undestand (not even feeding it to MySQL would work! &#8230;.</p>
<p>At this point I needed to do some compromises in order to reduce the complexity of this job, i.e. I will not be creating and altering tables / databases or indexes during runtime (this I can do without as I can do the same things on the slave manually when I need to do anything like that on the master) and the replication won&#8217;t be in real time i.e. the slave will be fed the sql periodically through a script. The last compromise wasn&#8217;t actually a compromise but a decision based on speed of coding as I&#8217;m more proficient in bash than perl and as such I decided to go with bash as a proof of concept that this thing can be done. This would never happen in reality as it would be much slower as compared to coding the same thing in perl or C / C++ (choice is up to you).</p>
<p>Now parsing the binary logs is not rocket science is it? As you can see there are three hashes &#8216;###&#8217; in front of the readable query so a simple grep is fine. A few subsitutions and text processing and you&#8217;ll end up with:</p>
<blockquote><p>
darrencassar@mysqlpreacher $ /home/dcassar/sandbox/5.1.30/bin/mysqlbinlog  | sed &#8217;s/^ *//g&#8217; | tr &#8216;\015\012&#8242; &#8216;\020 &#8216; | sed &#8217;s/ INSERT/;\nINSERT/g&#8217; | sed &#8217;s/ DELETE/;\nDELETE/g&#8217; | sed &#8217;s/ UPDATE/;\nUPDATE/g&#8217; | sed &#8216;${/^$/!s/$/;\<br />
&gt; /;}&#8217;<br />
INSERT INTO test.t1 SET @1=1 @2=&#8217;a';<br />
DELETE FROM test.t1 WHERE @1=1 @2=&#8217;a';<br />
INSERT INTO test.t2 SET @1=2 @2=&#8217;d';<br />
UPDATE test.t2 WHERE @1=2 @2=&#8217;d&#8217; SET @1=4 @2=&#8217;d';<br />
INSERT INTO test.t2 SET @1=1 @2=NULL;<br />
UPDATE test.t2 WHERE @1=4 @2=&#8217;d&#8217; SET @1=2 @2=&#8217;d';<br />
UPDATE test.t2 WHERE @1=1 @2=NULL SET @1=2 @2=NULL ;<br />
darrencassar@mysqlpreacher $
</p></blockquote>
<p>That is more readable but still not correctly formatted for our ANSI SQL slave.</p>
<blockquote><p>
`INSERT INTO test.t1 SET @1=1 @2=&#8217;a';` would need to be replaced with `INSERT INTO test.t1 (cola, colb) values(1,&#8217;a');` or `INSERT INTO test.t1 values(1,&#8217;a');`,<br />
`DELETE FROM test.t1 WHERE @1=1 @2=&#8217;a';` would need to be replaced with `DELETE FROM test.t1 WHERE cola=1 AND colb=&#8217;a';` and<br />
`UPDATE test.t2 WHERE @1=2 @2=&#8217;d&#8217; SET @1=4 @2=&#8217;d';` would have to become `UPDATE test.t2 SET cola=4 , colb=&#8217;d&#8217; WHERE cola=2 AND colb=&#8217;d';`
</p></blockquote>
<p>The above means we need to replace @1 and @2 with the appropriate column names done using a lookup table in my case by placing a files in data/dbname each bearing names of the different tables and listing each column in order:<br />
I.E. for a database named test and table named table1 having columns cola and colb I used the database folder named test in the mysql data folder and placed a file named table1, the contents of which were:</p>
<blockquote><p>cola<br />
colb</p></blockquote>
<p>The following piece of code does the job of replacing those dreadful @1, @2 etc with proper table names:</p>
<blockquote><p>
for (( i=1; i&lt;=`wc -l $dbname/$tbname | cut -d &#8221; &#8221; -f 1`; i++ ))<br />
do<br />
columnname=`awk &#8216;NR==a&#8217; a=$i $dbname/$tbname`<br />
LINE_TEMP=`echo $LINE_TEMP | sed &#8217;s/@&#8217;$i&#8217;=/AND &#8216;$columnname&#8217;=/g&#8217; | sed &#8217;s/SET AND/SET/g&#8217; | sed &#8217;s/WHERE AND/WHERE/g&#8217;`<br />
done
</p></blockquote>
<p>If you were thinking how I extracted dbname and tbname, here it is:</p>
<blockquote><p>
dbname=`echo $LINE | cut -d &#8221; &#8221; -f$col | cut -d &#8220;.&#8221; -f 1`<br />
tbname=`echo $LINE | cut -d &#8221; &#8221; -f$col | cut -d &#8220;.&#8221; -f 2`
</p></blockquote>
<p>where $LINE is each line extracted using the first command parsing mysqlbinary output and the variable col is 3 for delete and 2 for update which reflects the positioning of the database name and table name inside the extracted lines.</p>
<p>A rather ugly way of re-ordering the update command yet functional is:</p>
<blockquote><p>
echo $LINE_TEMP | cut -d &#8220;.&#8221; -f2 | sed &#8217;s/&#8217;$tbname&#8217; //&#8217; | sed &#8217;s/;//&#8217; &gt; templinefile<br />
cat templinefile | sed &#8217;s/ SET /\nSET /g&#8217; &gt; templinefile2<br />
LINE_TEMP=&#8221;UPDATE $dbname.$tbname `tail -1 templinefile2  | sed &#8217;s/ is NULL/=NULL/g&#8217; | sed &#8217;s/AND/,/g&#8217;` `head -1 templinefile2`;&#8221;
</p></blockquote>
<p>The last thing to remember is taking care of `=NULL` and replace it by `is NULL`.</p>
<blockquote><p>
LINE_TEMP=`echo $LINE_TEMP | sed &#8217;s/=NULL/ is NULL/g&#8217;`
</p></blockquote>
<p>As I said this was a fast proof of concept rather than a full fledged optimized script doing the job! The total length of code is 37 lines (excluding comments but with correct and nead formatting).</p>
<p>Enjoy<br />
Darren</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/05/replicating-from-mysql-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Installing: Binary tarball (.tar.gz) *nix based platforms</title>
		<link>http://mysqlpreacher.com/wordpress/2009/01/mysql-installing-binary-tarball-targz-nix-based-platforms/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/01/mysql-installing-binary-tarball-targz-nix-based-platforms/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 23:38:20 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[securing]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=50</guid>
		<description><![CDATA[Installing MySQL is quite an easy thing to do, especially when done using pkgs, dmgs or exes. It gets just a tad more time consuming and brain intensive when installing a .tar.gz binary package. It is when you&#8217;re compiling MySQL source directly that you&#8217;ll need some planning and playing, but the latter is only done [...]]]></description>
			<content:encoded><![CDATA[<p>Installing MySQL is quite an easy thing to do, especially when done using pkgs, dmgs or exes. It gets just a tad more time consuming and brain intensive when installing a .tar.gz binary package. It is when you&#8217;re compiling MySQL source directly that you&#8217;ll need some planning and playing, but the latter is only done in particular cases such as when you&#8217;ll need a particular engine not shipped with a pre-compiled package etc.</p>
<p>Today we&#8217;re going through the steps required for a typical MySQL installation from a .tar.gz package on a *nix based platform, including the download, installation, configuration and securing.</p>
<p>Steps involved:<br />
1. Download MySQL binary tarball from mysql.com<br />
2. Create a folder structure where the installation will be held.<br />
3. Install the package<br />
4. Secure the installation</p>
<p>Step 1: Download MySQL</p>
<p>Go to http://dev.mysql.com/downloads/ and choose the particular version that suits your platform (OS and machine type). Do note that installing a 32 bit version of MySQL on a 64 bit machine will not give you the full power available. There is quite a bit of performance impact when going for 64 bit, so if possible install the 64 bit version.</p>
<p>Step 2: Set up a folder structure to hold the MySQL related files</p>
<p>Normally in any database server I like to create a /mysql which will be holding any MySQL related info including, the releases, installation, configuration, data, logs etc. The below is a just personal choice and is subject to your liking. A typical folder structure would be</p>
<p>/mysql/ -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;applications -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maatkit<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sandbox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etc<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doc -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MySQL books<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RefMans<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etc</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;installations -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_cnf -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysqlpreacher_master_malta_3306<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysqlpreacher_slave_malta_3406<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etc</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_data -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysqlpreacher_master_malta_3306<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysqlpreacher_slave_malta_3406</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_dist -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_inst -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mysql_logs -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;..</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;releases -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5.0<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5.1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6.0</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;testing -&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perl<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sandbox<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scripts<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;etc</p>
<p>Step 3: Installing MySQL</p>
<p>The installation part takes just a few standard commands which follow:</p>
<p>#Execute the following only if you don&#8217;t already have a mysql user and mysql group. If you are not sure run: `cat /etc/group | grep -i mysql` and `cat /etc/group | grep -i mysql`. The &#8216;grep -i&#8217; permits you to find just the user mysql or variant of it including those of a different case.</p>
<blockquote><p><code>mysqlpreacher:~ darrencassar$ cat /etc/group | grep -i mysql<br />
_mysql:*:74:<br />
mysqlpreacher:~ darrencassar$ cat /etc/passwd | grep -i mysql<br />
_mysql:*:74:74:MySQL Server:/var/empty:/usr/bin/false</code></p></blockquote>
<p>#groupadd mysql<br />
#useradd -g mysql mysql</p>
<p>#Let&#8217;s assume you followed the above folder structure</p>
<p>cd /mysql/releases/5.1<br />
ls<br />
gunzip mysql-5.1.xx-xxx-xx.tar.gz<br />
tar -xf mysql-5.1.xx-xxx-xx.tar<br />
ls</p>
<blockquote><p><code>mysqlpreacher:~ darrencassar$ cd /mysql/releases/5.1/<br />
mysqlpreacher:5.1 darrencassar$ ls<br />
5.1.26                    mysql-5.1.26-rc-osx10.5-x86_64.dmg    mysql-5.1.28-rc-osx10.5-x86.tar.gz<br />
5.1.28                    mysql-5.1.26-rc-osx10.5-x86_64.tar.gz    mysql-5.1.30-osx10.5-x86_64.tar.gz<br />
mysqlpreacher:5.1 darrencassar$ gunzip mysql-5.1.30-osx10.5-x86_64.tar.gz<br />
mysqlpreacher:5.1 darrencassar$ tar -xf mysql-5.1.30-osx10.5-x86_64.tar<br />
mysqlpreacher:5.1 darrencassar$ ls<br />
5.1.26                    mysql-5.1.26-rc-osx10.5-x86_64.dmg    mysql-5.1.28-rc-osx10.5-x86.tar.gz    mysql-5.1.30-osx10.5-x86_64.tar<br />
5.1.28                    mysql-5.1.26-rc-osx10.5-x86_64.tar.gz    mysql-5.1.30-osx10.5-x86_64</code></p></blockquote>
<p>mv mysql-5.1.xx-xxx-xx ../../installations/mysql_inst/<br />
cd /mysql/installations/mysql_inst/<br />
mv mysql-5.1.xx-xxx-xx mysql-5.1.xx-xxx-xx_001</p>
<blockquote><p><code>mysqlpreacher:5.1 darrencassar$ mv mysql-5.1.30-osx10.5-x86_64 ../../installations/mysql_inst/<br />
mysqlpreacher:5.1 darrencassar$ cd /mysql/installations/mysql_inst/<br />
mysqlpreacher:mysql_inst darrencassar$ mv mysql-5.1.30-osx10.5-x86_64 mysql-5.1.30-osx10.5-x86_64_001</code></p></blockquote>
<p>#set up your naming convention, this is a way I find useful to work with myself<br />
ln -s mysql-5.1.xx-xxx-xx_001 mysql_51xx_001<br />
cd mysql_51xx_001</p>
<blockquote><p><code>mysqlpreacher:mysql_inst darrencassar$ ln -s mysql-5.1.30-osx10.5-x86_64_001 mysql_5130_001<br />
mysqlpreacher:mysql_inst darrencassar$ cd mysql_5130_001</code></p></blockquote>
<p>#set ownerships and permissions<br />
sudo chown -R mysql .<br />
sudo chgrp -R mysql .</p>
<blockquote><p><code>mysqlpreacher:mysql_5130_001 darrencassar$ sudo chown -R mysql .<br />
mysqlpreacher:mysql_5130_001 darrencassar$ sudo chgrp -R mysql .</code></p></blockquote>
<p>#Install the MySQL using mysql_install_db<br />
sudo scripts/mysql_install_db &#8211;user=mysql</p>
<blockquote><p><code>mysqlpreacher:mysql_5130_001 darrencassar$ sudo scripts/mysql_install_db --user=mysql<br />
WARNING: The host 'mysqlpreacher' could not be looked up with resolveip.<br />
This probably means that your libc libraries are not 100 % compatible<br />
with this binary MySQL version. The MySQL daemon, mysqld, should work<br />
normally with the exception that host name resolving will not work.<br />
This means that you should use IP addresses instead of hostnames<br />
when specifying MySQL privileges !<br />
Installing MySQL system tables...<br />
OK<br />
Filling help tables...<br />
OK<br />
</code><code><br />
To start mysqld at boot time you have to copy<br />
support-files/mysql.server to the right place for your system<br />
</code><code><br />
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !<br />
To do so, start the server, then issue the following commands:<br />
</code><code><br />
./bin/mysqladmin -u root password 'new-password'<br />
./bin/mysqladmin -u root -h mysqlpreacher password 'new-password'<br />
</code><code><br />
Alternatively you can run:<br />
./bin/mysql_secure_installation<br />
</code><code><br />
which will also give you the option of removing the test<br />
databases and anonymous user created by default.  This is<br />
strongly recommended for production servers.<br />
</code><code><br />
See the manual for more instructions.<br />
</code><code><br />
You can start the MySQL daemon with:<br />
cd . ; ./bin/mysqld_safe &amp;<br />
</code><code><br />
You can test the MySQL daemon with mysql-test-run.pl<br />
cd ./mysql-test ; perl mysql-test-run.pl<br />
</code><code><br />
Please report any problems with the ./bin/mysqlbug script!<br />
</code><code><br />
The latest information about MySQL is available at http://www.mysql.com/<br />
Support MySQL by buying support/licenses from http://shop.mysql.com/</code></p></blockquote>
<p>sudo chown -R root .<br />
sudo chown -R mysql data</p>
<blockquote><p><code>mysqlpreacher:mysql_5130_001 darrencassar$ sudo chown -R root .<br />
mysqlpreacher:mysql_5130_001 darrencassar$ sudo chown -R mysql data</code></p></blockquote>
<p>#provide a link from the data folder onto the mysql_data folder<br />
cd /mysql/installations/mysql_data/<br />
ln -s  /mysql/installations/mysql_inst/mysql_51xx_001/data/ data_51xx_001</p>
<p>cd /mysql/installations/mysql_inst/mysql_51xx_001/<br />
sudo su</p>
<blockquote><p><code>mysqlpreacher:mysql_5130_001 darrencassar$ cd /mysql/installations/mysql_data/<br />
mysqlpreacher:mysql_data darrencassar$ ln -s /mysql/installations/mysql_inst/mysql_5130_001/data/ data_5130_001<br />
mysqlpreacher:mysql_data darrencassar$ cd /mysql/installations/mysql_inst/mysql_5130_001<br />
mysqlpreacher:mysql_5130_001 darrencassar$ mkdir /mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/<br />
mysqlpreacher:mysql_5130_001 darrencassar$ cp -rp support-files/my-small.cnf /mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf<br />
mysqlpreacher:mysql_5130_001 darrencassar$ sudo su<br />
Password:<br />
sh-3.2# pwd<br />
/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001</code></p></blockquote>
<p>#Depending upon the size of your dataset, a generic my.cnf to use (options file where you set specific parameters which are read by MySQL before starting up) can be obtained from the support-files folder. This file normally requires quite some tweaking depending on the hardware, dataset, type of application querying the database, etc. Configuration is not a one time task either since things change with time, and so must the parameters set in this file.</p>
<p>#The generic samples of my.cnf are:<br />
my-small.cnf, my-medium.cnf, my-large.cnf, and my-huge.cnf</p>
<p>#Unless the location of the options file described above is hardcoded in the startup script (mysql.server), the order by which MySQL looks for a my.cnf is:</p>
<p>Filename                            Purpose</p>
<p>/etc/my.cnf                       Options<br />
/etc/mysql/my.cnf            Global options (as of MySQL 5.1.15)<br />
SYSCONFDIR/my.cnf          Global options<br />
$MYSQL_HOME/my.cnf      Server-specific options<br />
defaults-extra-file             The file specified with &#8211;defaults-extra-file=path, if any<br />
~/.my.cnf                          User-specific options</p>
<p>#Once the installation is complete, just start MySQL using:<br />
sudo bin/mysqld_safe  &#8211;defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf &#8211;user=mysql &amp;<br />
#note that the &#8211;defaults-file needs to be the first parameter in this command otherwise you&#8217;ll see an error “Too many arguments (first extra is &#8216;–defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf&#8217;).”</p>
<p>#you can check if MySQL did indeed start using the following<br />
ps -ef | grep -i mysql</p>
<blockquote><p><code>sh-3.2# sudo bin/mysqld_safe  --defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf --user=mysql &amp;<br />
[1] 88880<br />
sh-3.2# 090105 03:19:09 mysqld_safe Logging to '/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data/mysqlpreacher.err'.<br />
090105 03:19:09 mysqld_safe Starting mysqld daemon with databases from /mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data<br />
</code><code><br />
sh-3.2# ps -ef | grep -i mysql<br />
0 88880 88282   0   0:00.02 ttys001    0:00.04 /bin/sh bin/mysqld_safe --defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf --user=mysql<br />
74 88992 88880   0   0:00.04 ttys001    0:00.12 /mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/bin/mysqld --defaults-file=/mysql/installations/mysql_cnf/mysqlpreacher_master_malta_3306/my.cnf --basedir=/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001 --datadir=/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data --user=mysql --log-error=/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data/mysqlpreacher.err --pid-file=/mysql/installations/mysql_inst/mysql-5.1.30-osx10.5-x86_64_001/data/mysqlpreacher.pid --socket=/tmp/mysql.sock --port=3306<br />
0 89007 88282   0   0:00.00 ttys001    0:00.00 grep -i mysql</code></p></blockquote>
<p>Step 4: Secure the installation</p>
<p>When a database is placed online it does require some careful securing since it would otherwise be vulnerable to malicious acts such as alterations and denial of service.</p>
<p>MySQL uses Access Controlled Lists in order to discriminate between users, that means each user is given access to perform certain tasks while prohibited from doing others. It is quite flexible but managing fine grained rights allocation to a lot of users can also become quite a nightmare (consult maatkit mk_show_grants at http://www.maatkit.org/doc/mk-show-grants.html for this kind of setup). A MySQL command helpful in the latter task is:<br />
SHOW GRANTS FOR &#8216;user&#8217;@'host&#8217;;</p>
<p>Using GRANT and REVOKE will permit you to set privileges for individual users e.g.<br />
In order to grant select to john on database FOO while connected via localhost, the command would be:<br />
GRANT SELECT ON FOO.* TO &#8216;john&#8217;@'localhost&#8217; IDENTIFIED BY &#8216;password&#8217;;<br />
FLUSH PRIVILEGES;</p>
<p>Note that omitting the &#8216;identified by&#8217; would cause a user to have access without a password, something which should never be permitted for an online live server.</p>
<p>A further security measure, apart from ACL described above is to place MySQL server behind a firewall, preferably inside a DMZ (demilitarized zone) and should the MySQL server be accessible only through the socket file, then it would be a good idea to insert &#8217;skip-networking&#8217; in the configuration file my.cnf thus disabling any client from accessing the instance from any machine other than the machine on which it is installed.</p>
<p>One last suggestion as regards the security topic, consult MySQL updates and security patches in case there is something which directly impacts your current setup so that you can upgrade immediately if you are vulnerable in any way.</p>
<p>#access MySQL directly can be done using<br />
bin/mysql -u root -p<br />
SHOW DATABASES;</p>
<p>#If running a live MySQL system, run `drop database test`, you can always execute `create database test` later</p>
<p>#Create a password for root<br />
USE MYSQL;</p>
<p>UPDATE user<br />
SET Password = PASSWORD(&#8220;password&#8221;)<br />
WHERE User=&#8217;root&#8217;;</p>
<p>FLUSH PRIVILEGES;<br />
EXIT</p>
<p>#checking MySQL password set earlier<br />
bin/mysql -u root -p #don&#8217;t insert a password to test it out<br />
bin/mysql -u root -p #&#8230;. insert the new password (“password” in our case)</p>
<p>#It is good practice to set up a monitoring script which queries MySQL for any user without a password or for anonymous users.</p>
<p>USE MYSQL;<br />
SELECT User, Host, Password<br />
FROM user<br />
WHERE User=&#8221; OR Host=&#8221; OR Password=&#8221;;</p>
<p>#This should be remedied using:<br />
DELETE FROM user<br />
WHERE User=&#8221;;</p>
<blockquote><p><code>sh-3.2# bin/mysql -u root -p<br />
Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 1<br />
Server version: 5.1.30 MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
mysql&gt; SHOW DATABASES;<br />
+--------------------+<br />
| Database           |<br />
+--------------------+<br />
| information_schema |<br />
| mysql              |<br />
| test               |<br />
+--------------------+<br />
3 rows in set (0.02 sec)<br />
</code><code><br />
mysql&gt; USE MYSQL;<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A<br />
</code><code><br />
Database changed<br />
mysql&gt; UPDATE user<br />
-&gt; SET Password = PASSWORD("password")<br />
-&gt; WHERE User='root';<br />
Query OK, 3 rows affected (0.04 sec)<br />
Rows matched: 3  Changed: 3  Warnings: 0<br />
</code><code><br />
mysql&gt; FLUSH PRIVILEGES;<br />
Query OK, 0 rows affected (0.02 sec)<br />
</code><code><br />
mysql&gt; EXIT<br />
Bye<br />
sh-3.2# bin/mysql -u root -p<br />
Enter password:<br />
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)<br />
sh-3.2# bin/mysql -u root -p<br />
Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 3<br />
Server version: 5.1.30 MySQL Community Server (GPL)<br />
</code><code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br />
</code><code><br />
mysql&gt; USE MYSQL;<br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A<br />
</code><code><br />
Database changed<br />
mysql&gt; SELECT User, Host, Password<br />
-&gt; FROM user<br />
-&gt; WHERE User='' OR Host='' OR Password='';<br />
+------+---------------+----------+<br />
| User | Host          | Password |<br />
+------+---------------+----------+<br />
|      | localhost     |          |<br />
|      | mysqlpreacher |          |<br />
+------+---------------+----------+<br />
2 rows in set (0.00 sec)<br />
</code><code><br />
mysql&gt; DELETE FROM user<br />
-&gt; WHERE User='';<br />
Query OK, 2 rows affected (0.02 sec)<br />
</code><code><br />
mysql&gt; SELECT User, Host, Password<br />
-&gt; FROM user<br />
-&gt; WHERE User='' OR Host='' OR Password='';<br />
Empty set (0.00 sec)<br />
</code><code><br />
mysql&gt; \q<br />
Bye<br />
sh-3.2#</code></p></blockquote>
<p>This section does not exhaust all security guidelines of course, but helps making your instance more secure.</p>
<p>#DONE</p>
<p>&#8212;&#8212;&#8212;&#8211; o &#8212;&#8212;&#8212;&#8211;</p>
<p>#A few general notes:</p>
<p>#Note that not all the MySQL commands need a &#8216;;&#8217; at the end, an example is `\s` and `SHOW STATUS \G`<br />
#Exiting from MySQL can be done using `EXIT` or `QUIT` or `\q`<br />
#A helpful command to get you started is `?` which provides a list of commands available</p>
<p>#There are many other commands and combination of syntaxes which you can write in order to obtain results</p>
<p>#It is good practice to insert MySQL path in the env variable PATH in order to avoid typing the whole path each time you want to use MySQL. In bash you&#8217;d do:</p>
<p>export PATH=/path/to/mysql/bin:$PATH</p>
<p>o insert the MySQL&#8217;s path before all the others, otherwise just interchange the positions of $PATH and the actual /path/to/mysql/bin</p>
<p>#Killing the MySQL is done using the following command:<br />
bin/mysqladmin -u root -p shutdown</p>
<p>#Starting and stopping MySQL automatically can be done using mysql.server, found in support-files folder. The file needs to be copied in /etc/rc.d and edited to insert the custom parameters of data directory, base directory etc.</p>
<p>#If the storage engine used is innodb, a good my.cnf option would be innodb_file_per_table since otherwise innodb will store all it&#8217;s table data in a single file which is not optimal when having big tables which need to be optimzed / analyzed.</p>
<p>#Remember to set up monitoring scripts should this be a live system in order to avoid downtime.</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/01/mysql-installing-binary-tarball-targz-nix-based-platforms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
