<?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; Advanced</title>
	<atom:link href="http://mysqlpreacher.com/wordpress/category/databases/mysql/advanced/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>Datetime &amp; Timestamp manipulation / migration explained</title>
		<link>http://mysqlpreacher.com/wordpress/2010/06/datetime-timestamp-manipulation-migration-explained/</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/06/datetime-timestamp-manipulation-migration-explained/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 16:47:16 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[date_format]]></category>
		<category><![CDATA[microsecond]]></category>
		<category><![CDATA[migrating to mysql]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[millisecond]]></category>
		<category><![CDATA[mysql millisecond]]></category>
		<category><![CDATA[str_to_date]]></category>
		<category><![CDATA[timstamp]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=351</guid>
		<description><![CDATA[Are you doing some datetime manipulation or maybe you are migrating from some database technology to MySQL or possibly using milliseconds?
Here is an example on how to go about it:
Say you have the following date: MAR 16 2008 09:12:51:893AM
SELECT DATE_FORMAT(STR_TO_DATE('MAR 16 2008 09:12:51:893AM','%M %d %Y %h:%i:%s:%f%p'),'%Y%m%d%k%i%s.%f'); --&#62; 2008031691251.893000

What if its PM rather than AM
SELECT DATE_FORMAT(STR_TO_DATE('MAR [...]]]></description>
			<content:encoded><![CDATA[<p>Are you doing some datetime manipulation or maybe you are migrating from some database technology to MySQL or possibly using milliseconds?<br />
Here is an example on how to go about it:</p>
<p>Say you have the following date: MAR 16 2008 09:12:51:893AM<br />
<code>SELECT DATE_FORMAT(STR_TO_DATE('MAR 16 2008 09:12:51:893AM','%M %d %Y %h:%i:%s:%f%p'),'%Y%m%d%k%i%s.%f'); --&gt; 2008031691251.893000<br />
</code></p>
<p>What if its PM rather than AM<br />
<code>SELECT DATE_FORMAT(STR_TO_DATE('MAR 16 2008 09:12:51:893PM','%M %d %Y %h:%i:%s:%f%p'),'%Y%m%d%k%i%s.%f'); --&gt; 20080316211251.893000<br />
</code></p>
<p>Ok so this is just simple string manipulation where:<br />
<code>%M is the month name<br />
%d is day number<br />
%Y is the year<br />
%h is the hour<br />
%i is the minute<br />
%s is the second<br />
%f is the microsecond<br />
%p is the period: ante or post meridiem</code><br />
In the DATE_FORMAT part we se a %k which is in 24hr format in order to loose the period.</p>
<p>A more detailed list is found <a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format" target="_blank">here</a></p>
<p>Here is a demo:</p>
<p><code>mysql Tue Jun 15 12:32:37 2010 &gt; CREATE TABLE test.abc(a DECIMAL(17,3)) ENGINE=MYISAM;<br />
Query OK, 0 rows affected (0.03 sec)</code></p>
<p><code>mysql Tue Jun 15 12:32:45 2010 &gt; INSERT INTO abc VALUES ( DATE_FORMAT(STR_TO_DATE('MAR 16 2008 09:12:51:893PM','%M %d %Y %h:%i:%s:%f%p'),'%Y%m%d%k%i%s.%f') );<br />
Query OK, 1 row affected (0.01 sec)</code></p>
<p><code>mysql Tue Jun 15 12:32:51 2010 &gt; SELECT * FROM abc;<br />
+--------------------+<br />
| a                  |<br />
+--------------------+<br />
| 20080316211251.893 |<br />
+--------------------+<br />
1 row in set (0.00 sec)</p>
<p></code></p>
<p><code>mysql Tue Jun 15 12:32:56 2010 &gt; SELECT TIMESTAMP(a) FROM abc;<br />
+----------------------------+<br />
| TIMESTAMP(a)               |<br />
+----------------------------+<br />
| 2008-03-16 21:12:51.893000 |<br />
+----------------------------+<br />
1 row in set (0.00 sec)</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2010/06/datetime-timestamp-manipulation-migration-explained/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>MCDBA Certification &#8211; KPIs</title>
		<link>http://mysqlpreacher.com/wordpress/2009/03/mcdba-certification-kpis/</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/03/mcdba-certification-kpis/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 16:15:58 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Advanced]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[certification]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[kpis]]></category>
		<category><![CDATA[MCDBA]]></category>
		<category><![CDATA[MySQL certified dba]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=128</guid>
		<description><![CDATA[A few interesting KPIs about certified people and their current location (the fact that many people travel from one country to the other for work is very popular these days especially in the IT sector):
Before starting to read, I am hereby assuming the MySQL list of MCDBAs is on a residence basis not citizenship.
There are [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">A few interesting KPIs about certified people and their current location (the fact that many people travel from one country to the other for work is very popular these days especially in the IT sector):</p>
<p style="text-align: left;">Before starting to read, I am hereby assuming the MySQL list of MCDBAs is on a residence basis not citizenship.</p>
<p style="text-align: left;">There are at the time of this writing a total of 796 MCDBAs in the world, living in 57 countries.</p>
<p style="text-align: left;">When analyzing the number of MCDBAs / country, it is pretty obvious the scene is totally dominated by the US:</p>
<p style="text-align: left;"><a href="http://mysqlpreacher.com/wordpress/wp-content/uploads/2009/03/no_country1.jpg"><img class="size-full wp-image-138 aligncenter" title="MCDBA Certification KPIs / Country" src="http://mysqlpreacher.com/wordpress/wp-content/uploads/2009/03/no_country1.jpg" alt="" width="500" height="414" /></a></p>
<p><code>+----------------------+-------------+</code><br />
<code>| Country              | No of Certs |</code><br />
<code>+----------------------+-------------+</code><br />
<code>| UnitedStates         |         346 | </code><br />
<code>| Unitedkingdom        |          47 | </code><br />
<code>| Germany              |          46 | </code><br />
<code>| India                |          34 | <br />
| Italy                |          28 | <br />
| Japan                |          26 | <br />
| Canada               |          23 | <br />
| China                |          20 | <br />
| Brazil               |          18 | <br />
| Australia            |          16 | <br />
| France               |          16 | <br />
| Netherlands          |          13 | <br />
| Switzerland          |          13 | <br />
| SouthKorea           |          12 | <br />
| Spain                |          11 | <br />
| HongKong             |          10 | <br />
| Sweden               |          10 | <br />
| SouthAfrica          |          10 | <br />
| Singapore            |           9 | <br />
| Taiwan               |           8 | <br />
| Poland               |           7 | <br />
| Philippines          |           6 | <br />
| Norway               |           5 | <br />
| Russia               |           5 | <br />
| Finland              |           5 | <br />
| Ireland              |           4 | <br />
| Israel               |           3 | <br />
| Srilanka             |           3 | <br />
| Ukraine              |           3 | <br />
| Austria              |           3 | <br />
| Belgium              |           3 | <br />
| Denmark              |           2 | <br />
| Egypt                |           2 | <br />
| Mexico               |           2 | <br />
| Malta                |           2 | <br />
| Thailand             |           2 | <br />
| Unitedarabemirates   |           2 | <br />
| Latvia               |           2 | <br />
| Bangladesh           |           1 | <br />
| Croatia              |           1 | <br />
| TrinidadandTobago    |           1 | <br />
| BosniaandHerzegovina |           1 | <br />
| Malaysia             |           1 | <br />
| Slovenia             |           1 | <br />
| SaudiArabia          |           1 | <br />
| Indonesia            |           1 | <br />
| Jordan               |           1 | <br />
| Kenya                |           1 | <br />
| Lithuania            |           1 | <br />
| Luxembourg           |           1 | <br />
| Guatemala            |           1 | <br />
| Nepal                |           1 | <br />
| Gibraltar            |           1 | <br />
| Newzealand           |           1 | <br />
| Pakistan             |           1 | <br />
| Portugal             |           1 | <br />
| Virginislands        |           1 | <br />
<code>+----------------------+-------------+ <br />
</code></code></p>
<p><code> </code></p>
<p><code></p>
<p style="text-align: left;">But what happens when we look at the number of MCDBAS in respect to population / area?</p>
<p style="text-align: left;">The country with largest certs / capita is Gibralter with a MySQL Certified DBA in 31k population, followed by Virgin Islands at 1 for 110k and Malta at 2 / 412.6k.</p>
<p style="text-align: left;">The country with least certs / capita is Indonesia with a single MySQL Certified DBA out of almost 230M people.</p>
<p style="text-align: left;"><span style="text-decoration: underline;"><a href="http://mysqlpreacher.com/wordpress/wp-content/uploads/2009/03/no_population1.jpg"><img class="aligncenter size-full wp-image-139" title="MCDBA Certification KPIs / population" src="http://mysqlpreacher.com/wordpress/wp-content/uploads/2009/03/no_population1.jpg" alt="" width="500" height="607" /></a><br />
</span><br />
<code>+----------------------+------------+-------------+---------+</code><br />
<code>| Country              | Population | No of Certs | PPM     |</code><br />
<code>+----------------------+------------+-------------+---------+</code><br />
<code>| Gibraltar            |      31000 |           1 | 32.2580 | </code><br />
<code>| Virgin Islands       |     110000 |           1 |  9.0900 | </code><br />
<code>| Malta                |     412600 |           2 |  4.8470 | </code><br />
<code>| Luxembourg           |     491700 |           1 |  2.0330 | </code><br />
<code>| Singapore            |    4839400 |           9 |  1.8590 | <br />
| Switzerland          |    7700200 |          13 |  1.6880 | <br />
| Hong Kong            |    6985200 |          10 |  1.4310 | <br />
| United States        |  306088000 |         346 |  1.1300 | <br />
| Sweden               |    9259828 |          10 |  1.0790 | <br />
| Norway               |    4810122 |           5 |  1.0390 | <br />
| Finland              |    5331096 |           5 |  0.9370 | <br />
| Ireland              |    4517800 |           4 |  0.8850 | <br />
| Latvia               |    2260000 |           2 |  0.8840 | <br />
| Netherlands          |   16492476 |          13 |  0.7880 | <br />
| United Kingdom       |   61612300 |          47 |  0.7620 | <br />
| Trinidad and Tobago  |    1339000 |           1 |  0.7460 | <br />
| Australia            |   21707964 |          16 |  0.7370 | <br />
| Canada               |   33596000 |          23 |  0.6840 | <br />
| Germany              |   82062200 |          46 |  0.5600 | <br />
| Slovenia             |    2053355 |           1 |  0.4870 | <br />
| Italy                |   60090400 |          28 |  0.4650 | <br />
| United Arab Emirates |    4599000 |           2 |  0.4340 | <br />
| Israel               |    7382200 |           3 |  0.4060 | <br />
| Denmark              |    5511451 |           2 |  0.3620 | <br />
| Austria              |    8356700 |           3 |  0.3580 | <br />
| Taiwan               |   23027672 |           8 |  0.3470 | <br />
| Lithuania            |    3350400 |           1 |  0.2980 | <br />
| Belgium              |   10741000 |           3 |  0.2790 | <br />
| Bosnia Herzegovina   |    3767000 |           1 |  0.2650 | <br />
| South Korea          |   48333000 |          12 |  0.2480 | <br />
| France               |   65073482 |          16 |  0.2450 | <br />
| Spain                |   45853000 |          11 |  0.2390 | <br />
| New Zealand          |    4302010 |           1 |  0.2320 | <br />
| Croatia              |    4432000 |           1 |  0.2250 | <br />
| South Africa         |   48697000 |          10 |  0.2050 | <br />
| Japan                |  127630000 |          26 |  0.2030 | <br />
| Poland               |   38130300 |           7 |  0.1830 | <br />
| Jordan               |    6316000 |           1 |  0.1580 | <br />
| Sri Lanka            |   20238000 |           3 |  0.1480 | <br />
| Brazil               |  190902000 |          18 |  0.0940 | <br />
| Portugal             |   10631800 |           1 |  0.0940 | <br />
| Guatemala            |   14027000 |           1 |  0.0710 | <br />
| Philippines          |   92226600 |           6 |  0.0650 | <br />
| Ukraine              |   46143700 |           3 |  0.0650 | <br />
| Saudi Arabia         |   25721000 |           1 |  0.0380 | <br />
| Russia               |  141850000 |           5 |  0.0350 | <br />
| Malaysia             |   28067000 |           1 |  0.0350 | <br />
| Nepal                |   29331000 |           1 |  0.0340 | <br />
| Thailand             |   63389730 |           2 |  0.0310 | <br />
| India                | 1161120000 |          34 |  0.0290 | <br />
| Egypt                |   76030000 |           2 |  0.0260 | <br />
| Kenya                |   39802000 |           1 |  0.0250 | <br />
| Mexico               |  109610000 |           2 |  0.0180 | <br />
| China                | 1335962133 |          20 |  0.0140 | <br />
| Bangladesh           |  162221000 |           1 |  0.0060 | <br />
| Pakistan             |  165899500 |           1 |  0.0060 | <br />
| Indonesia            |  229850000 |           1 |  0.0040 | <br />
+----------------------+------------+-------------+---------+<br />
</code></p>
<p style="text-align: left;">On a per area basis, the country with most certified MySQL DBAs is again Gibralter given its 6Km squared of area, followed by Singapore, Hong Kong and Malta.</p>
<p style="text-align: left;">The least being Pakistan, Russia and Indonesia in order.</p>
<p style="text-align: left;"><a href="http://mysqlpreacher.com/wordpress/wp-content/uploads/2009/03/no_km1.jpg"><img class="aligncenter size-full wp-image-140" title="MCDBA Certification KPIs / 1000 Km squared" src="http://mysqlpreacher.com/wordpress/wp-content/uploads/2009/03/no_km1.jpg" alt="" width="500" height="541" /></a></p>
<p style="text-align: left;">*PPK here means parts per 1000 Km squared</p>
<p><code>+----------------------+----------+-------------+----------+</code><br />
<code>| Country              | Area     | No of Certs | PPK*     |</code><br />
<code>+----------------------+----------+-------------+----------+</code><br />
<code>| Gibraltar            |        6 |           1 | 166.6667 | </code><br />
<code>| Singapore            |      699 |           9 |  12.8755 | </code><br />
<code>| Hong Kong            |     1108 |          10 |   9.0253 | </code><br />
<code>| Malta                |      316 |           2 |   6.3291 | </code><br />
<code>| Virgin Islands       |      347 |           1 |   2.8818 | <br />
| Luxembourg           |     2586 |           1 |   0.3867 | <br />
| Switzerland          |    41284 |          13 |   0.3149 | <br />
| Netherlands          |    41543 |          13 |   0.3129 | <br />
| Taiwan               |    36188 |           8 |   0.2211 | <br />
| Trinidad and Tobago  |     5130 |           1 |   0.1949 | <br />
| United Kingdom       |   242900 |          47 |   0.1935 | <br />
| Israel               |    22072 |           3 |   0.1359 | <br />
| Germany              |   357022 |          46 |   0.1288 | <br />
| South Korea          |    99678 |          12 |   0.1204 | <br />
| Belgium              |    30528 |           3 |   0.0983 | <br />
| Italy                |   301318 |          28 |   0.0929 | <br />
| Japan                |   377915 |          26 |   0.0688 | <br />
| Ireland              |    70273 |           4 |   0.0569 | <br />
| Slovenia             |    20273 |           1 |   0.0493 | <br />
| Denmark              |    43094 |           2 |   0.0464 | <br />
| Sri Lanka            |    65610 |           3 |   0.0457 | <br />
| United States        |  9629091 |         346 |   0.0359 | <br />
| Austria              |    83871 |           3 |   0.0358 | <br />
| Latvia               |    64589 |           2 |   0.0310 | <br />
| France               |   632760 |          16 |   0.0253 | <br />
| United Arab Emirates |    83600 |           2 |   0.0239 | <br />
| Poland               |   312685 |           7 |   0.0224 | <br />
| Sweden               |   450295 |          10 |   0.0222 | <br />
| Spain                |   505992 |          11 |   0.0217 | <br />
| Philippines          |   300000 |           6 |   0.0200 | <br />
| Bosnia Herzegovina   |    51197 |           1 |   0.0195 | <br />
| Croatia              |    56594 |           1 |   0.0177 | <br />
| Norway               |   323802 |           5 |   0.0154 | <br />
| Lithuania            |    65300 |           1 |   0.0153 | <br />
| Finland              |   338145 |           5 |   0.0148 | <br />
| Jordan               |    89342 |           1 |   0.0112 | <br />
| Portugal             |    92090 |           1 |   0.0109 | <br />
| India                |  3287263 |          34 |   0.0103 | <br />
| Guatemala            |   108889 |           1 |   0.0092 | <br />
| South Africa         |  1221037 |          10 |   0.0082 | <br />
| Bangladesh           |   143998 |           1 |   0.0069 | <br />
| Nepal                |   147181 |           1 |   0.0068 | <br />
| Ukraine              |   603500 |           3 |   0.0050 | <br />
| Thailand             |   513120 |           2 |   0.0039 | <br />
| New Zealand          |   270467 |           1 |   0.0037 | <br />
| Malaysia             |   329847 |           1 |   0.0030 | <br />
| Canada               |  9984670 |          23 |   0.0023 | <br />
| Brazil               |  8514877 |          18 |   0.0021 | <br />
| Australia            |  7692024 |          16 |   0.0021 | <br />
| China                |  9640821 |          20 |   0.0021 | <br />
| Egypt                |  1002000 |           2 |   0.0020 | <br />
| Kenya                |   580367 |           1 |   0.0017 | <br />
| Mexico               |  1964375 |           2 |   0.0010 | <br />
| Saudi Arabia         |  2000000 |           1 |   0.0005 | <br />
| Indonesia            |  1904569 |           1 |   0.0005 | <br />
| Russia               | 17098242 |           5 |   0.0003 | <br />
| Pakistan             |  7960951 |           1 |   0.0001 | <br />
+----------------------+----------+-------------+----------+<br />
</code></p>
<p style="text-align: left;">At this point I'd like to ask the community a couple of questions:</p>
<p style="text-align: left;">1. Do you think there are many good MySQL DBAs who never tried getting certified?</p>
<p style="text-align: left;">2. Would you think it is fair to assume, the people who never tried the MCDBA exam is proportional to does who did? (my guess is yes)</p>
<p style="text-align: left;"> <br />
KPIs for developers and cluster certified people will follow in other blogs.</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2009/03/mcdba-certification-kpis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
