<?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>PlanetMysql.ru - информация о СУБД MySQL &#187; Intermediate</title>
	<atom:link href="http://planetmysql.ru/category/intermediate/feed/" rel="self" type="application/rss+xml" />
	<link>http://planetmysql.ru</link>
	<description>Блог о самой популярной СУБД MySQL</description>
	<lastBuildDate>Sat, 11 Feb 2012 12:38:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Recovering a MySQL `root` password – Three solutions</title>
		<link>http://mysqlpreacher.com/wordpress/2011/03/recovering-a-mysql-root-password-three-solutions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=recovering-a-mysql-root-password-%25e2%2580%2593-three-solutions</link>
		<comments>http://mysqlpreacher.com/wordpress/2011/03/recovering-a-mysql-root-password-three-solutions/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 19:01:22 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[authentication]]></category>
		<category><![CDATA[grants]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pass]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[skip-grant-tables]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[user.myd]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=657</guid>
		<description><![CDATA[Three ways to recover a root user password:
The order of solutions here under gets more creative on the way down :)
1. obviously, before starting messing around check my.cnf or scripts for passwords entries, then try home directories for password files
2. secondly &#8211; can you restart mysql? if yes, restart with &#8211;skip-grant-tables, log into mysql, change your password and restart without &#8211;skip-grant-tables
3. third option &#8211; (on linux / unix ONLY)
If you haven’t found the password anywhere and can&#8217;t afford to restart your mysql.
cd data/mysql
cp -rp user.MYD bck_user.MYD_`date +%Y%m%d`
cp -rp user.MYD /tmp/user.MYD
vi /tmp/user.MYD #(edit the hashed passwords next to root*)
cp -rp /tmp/user.MYD user.MYD
sudo kill -HUP `pidof mysqld`
Note that the latter method of recovering a root password CAN be easily used maliciously leaving no trace! The only way to avoid such an attack is to make the data directory ONLY readable and writable by the user used to start/stop mysql (don&#8217;t user *nix root user to own mysql since that opens another can of worms &#8230; it&#8217;s a whole other blog post).]]></description>
			<content:encoded><![CDATA[<p>Three ways to recover a root user password:</p>
<p>The order of solutions here under gets more creative on the way down :)</p>
<p>1. obviously, before starting messing around check my.cnf or scripts for passwords entries, then try home directories for password files<br />
2. secondly &#8211; can you restart mysql? if yes, restart with &#8211;skip-grant-tables, log into mysql, change your password and restart without &#8211;skip-grant-tables<br />
3. third option &#8211; (on linux / unix ONLY)<br />
If you haven’t found the password anywhere and can&#8217;t afford to restart your mysql.</p>
<pre>cd data/mysql
cp -rp user.MYD bck_user.MYD_`date +%Y%m%d`
cp -rp user.MYD /tmp/user.MYD
vi /tmp/user.MYD #(edit the hashed passwords next to root*)
cp -rp /tmp/user.MYD user.MYD
sudo kill -HUP `pidof mysqld`</pre>
<p>Note that the latter method of recovering a root password CAN be easily used maliciously leaving no trace! The only way to avoid such an attack is to make the data directory ONLY readable and writable by the user used to start/stop mysql (don&#8217;t user *nix root user to own mysql since that opens another can of worms &#8230; it&#8217;s a whole other blog post).</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=27666&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=27666&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/03/21/recovering-a-mysql-root-password-%e2%80%93-three-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CRIB – CentRal Information Base for MySQL</title>
		<link>http://mysqlpreacher.com/wordpress/2010/12/crib-central-information-base-for-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=crib-%25e2%2580%2593-central-information-base-for-mysql</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/12/crib-central-information-base-for-mysql/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 11:19:50 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[crib]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=562</guid>
		<description><![CDATA[CRIB is a CentRal Information Base for MySQL, a long time coming project since I worked on it on and off for a few weeks and now I decided it&#8217;s time to hand it over to the global MySQL community.
So, what is CRIB?
CRIB is a central database which collects information about all your MySQL instances which you set as clients. It is monitoring in a way, but not the typical number of connections, memory, index usage, table scans, cpu usage and such, but rather consists of a repository where, if you have tens, hundreds or even thousands of clients, you can see where a particular user was created, where a certain database name features or which tables does a database consists of. It also features a script which logs table sizes periodically (customizable) so you can graph disk usage over time and be able to forecast future disk space requirements easily.
Download the latest code with: bzr branch lp:crib
First of all lets create the user used to write to the server (mother instance)

[dcassar@ubt]$ use5151
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 5.1.51 MySQL Community Server (GPL)


Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql &#62; grant create, insert, alter, update, delete, select, drop, execute, create temporary tables, create routine, alter routine, lock tables on crib.* to "mother"@"%" identified by "teacher";
Query OK, 0 rows affected (0.02 sec)


mysql &#62; exit
Bye
[dcassar@ubt]$

Lets go ahead and install CRIB on both server and client

[dcassar@ubt]$ cd INSTALL
[dcassar@ubt]$ ./crib_install.sh

brought to you by Darren Cassar

Anytime you need to cancel installation just press ( Ctrl + C )

Would you like to setup source and destination or just source?
1. Client and Server
2. New Client
Enter choice (default 2): 1
Installation starting

This section you'll supply the destination (CentRal Information Base) details

Enter CRIB user name (default root): mother
Enter CRIB password (default 'toor'):
Enter CRIB hostname (default localhost): 127.0.0.1
Enter CRIB port (default 3306): 5151

This section you'll supply the client details

Enter client user name (default root): dcassar
Enter client password (default 'toor'):
Enter client hostname (default localhost): dolphin
Enter client port (default 3306): 3331
Installation complete
[dcassar@ubt]$

Now is the time to gather the data from the clients and log it onto the server.

[dcassar@ubt]$ ./populate.sh CONFIG/crib_3331.cnf
[dcassar@ubt]$ ./tablesize.sh CONFIG/crib_3331.cnf

Lets log into the CRIB database on the mother server and see what details we have at our disposal.

[dcassar@ubt]$ use5151
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 5.1.51 MySQL Community Server (GPL)


Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql &#62; use crib
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql &#62; show tables;
+------------------+
&#124; Tables_in_crib   &#124;
+------------------+
&#124; info_instances   &#124;
&#124; info_object_size &#124;
&#124; info_objects     &#124;
&#124; info_privileges  &#124;
&#124; info_users       &#124;
&#124; version          &#124;
+------------------+
6 rows in set (0.00 sec)

mysql &#62; select * from version;
+----+---------+---------------------+
&#124; ID &#124; VERSION &#124; UPDATED_TIMESTAMP   &#124;
+----+---------+---------------------+
&#124;  1 &#124; 0.1     &#124; 2010-12-09 16:24:05 &#124;
+----+---------+---------------------+
1 row in set (0.00 sec)

mysql &#62; select * from info_instances;
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+
&#124; id &#124; hostname                            &#124; port &#124; server_id &#124; mysql_version &#124; os              &#124; os_version &#124; architecture &#124; bits &#124; notes &#124;
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+
&#124;  1 &#124; dolphin                             &#124; 3331 &#124;  14123561 &#124; 5.1.50        &#124; sun-solaris2.10 &#124; 10         &#124; sparc        &#124;   64 &#124; NULL  &#124;
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+
1 row in set (0.00 sec)

From the above you realize you can identify all versions used in your setup, what hardware you are using, port numbers used and much more!
Lets see what users we have so far.

mysql &#62; select * from info_users;
+----+-------------+------------+---------------------------+-------------------------------------------+
&#124; id &#124; instance_id &#124; username   &#124; hostname                  &#124; password                                  &#124;
+----+-------------+------------+---------------------------+-------------------------------------------+
&#124;  1 &#124;           1 &#124; root       &#124; localhost                 &#124; *BA44AFCA02B64C198FAEB3043F47CA3797638975 &#124;
&#124;  2 &#124;           1 &#124; root       &#124; %.dev.domain.com          &#124; *BA44AFCA02B64C198FAEB3043F47CA3797638975 &#124;
&#124;  3 &#124;           1 &#124; root       &#124; 127.0.0.1                 &#124; *BA44AFCA02B64C198FAEB3043F47CA3797638975 &#124;
&#124;  4 &#124;           1 &#124; abc        &#124; %                         &#124; *A4456E2A03EC0EE4E164BFA533443E82691DA163 &#124;
&#124;  5 &#124;           1 &#124; def        &#124; localhost                 &#124; *5162BA4456B42A01FD8DDBB4CDBE46AFAD06C5AB &#124;
&#124;  6 &#124;           1 &#124; ghi        &#124; %                         &#124; *95E6C48AFC85167C37A24130DD4F5FE0F48AB658 &#124;
&#124;  7 &#124;           1 &#124; jkl        &#124; %                         &#124; *7A2D095E620E354F216EE00635E163406AD47392 &#124;
&#124;  8 &#124;           1 &#124; mno        &#124; %                         &#124;                                           &#124;
&#124;  9 &#124;           1 &#124; qpr        &#124; localhost                 &#124; *5162BA4456B42A01FD8DDBB4CDBE46AFAD06C5AB &#124;
+----+-------------+------------+---------------------------+-------------------------------------------+
9 rows in set (0.00 sec)

If we had multiple machines set up as clients then we would have another group with instance_id 2, so on and so forth.
Remember this is an alpha tool and whatever you do with it is your responsibility. You are advised NOT TO set this up on production for now.]]></description>
			<content:encoded><![CDATA[<p>CRIB is a CentRal Information Base for MySQL, a long time coming project since I worked on it on and off for a few weeks and now I decided it&#8217;s time to hand it over to the global MySQL community.</p>
<p>So, what is CRIB?</p>
<p>CRIB is a central database which collects information about all your MySQL instances which you set as clients. It is monitoring in a way, but not the typical number of connections, memory, index usage, table scans, cpu usage and such, but rather consists of a repository where, if you have tens, hundreds or even thousands of clients, you can see where a particular user was created, where a certain database name features or which tables does a database consists of. It also features a script which logs table sizes periodically (customizable) so you can graph disk usage over time and be able to forecast future disk space requirements easily.</p>
<p>Download the latest code with: <b>bzr branch lp:crib</b></p>
<p>First of all lets create the user used to write to the server (mother instance)</p>
<p><code><br />
[dcassar@ubt]$ use5151<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 56<br />
Server version: 5.1.51 MySQL Community Server (GPL)<br />
</code><br />
<code><br />
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.<br />
This software comes with ABSOLUTELY NO WARRANTY. This is free software,<br />
and you are welcome to modify and redistribute it under the GPL v2 license<br />
</code><br />
<code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.<br />
</code><br />
<code><br />
mysql &gt; grant create, insert, alter, update, delete, select, drop, execute, create temporary tables, create routine, alter routine, lock tables on crib.* to "mother"@"%" identified by "teacher";<br />
Query OK, 0 rows affected (0.02 sec)<br />
</code><br />
<code><br />
mysql &gt; exit<br />
Bye<br />
[dcassar@ubt]$<br />
</code></p>
<p>Lets go ahead and install CRIB on both server and client</p>
<p><code><br />
[dcassar@ubt]$ cd INSTALL<br />
[dcassar@ubt]$ ./crib_install.sh<br />
</code><br />
<code>brought to you by Darren Cassar<br />
</code><code><br />
Anytime you need to cancel installation just press ( Ctrl + C )<br />
</code><code><br />
Would you like to setup source and destination or just source?<br />
1. Client and Server<br />
2. New Client<br />
Enter choice (default 2): 1<br />
Installation starting<br />
</code><br />
<code>This section you'll supply the destination (CentRal Information Base) details<br />
</code><br />
<code>Enter CRIB user name (default root): mother<br />
Enter CRIB password (default 'toor'):<br />
Enter CRIB hostname (default localhost): 127.0.0.1<br />
Enter CRIB port (default 3306): 5151<br />
</code><br />
<code>This section you'll supply the client details<br />
</code><br />
<code>Enter client user name (default root): dcassar<br />
Enter client password (default 'toor'):<br />
Enter client hostname (default localhost): dolphin<br />
Enter client port (default 3306): 3331<br />
Installation complete<br />
[dcassar@ubt]$<br />
</code><br />
Now is the time to gather the data from the clients and log it onto the server.</p>
<p><code><br />
[dcassar@ubt]$ ./populate.sh CONFIG/crib_3331.cnf<br />
[dcassar@ubt]$ ./tablesize.sh CONFIG/crib_3331.cnf<br />
</code></p>
<p>Lets log into the CRIB database on the mother server and see what details we have at our disposal.</p>
<p><code><br />
[dcassar@ubt]$ use5151<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 56<br />
Server version: 5.1.51 MySQL Community Server (GPL)<br />
</code><br />
<code><br />
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.<br />
This software comes with ABSOLUTELY NO WARRANTY. This is free software,<br />
and you are welcome to modify and redistribute it under the GPL v2 license<br />
</code><br />
<code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.<br />
</code><code><br />
mysql &gt; use crib<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; show tables;<br />
+------------------+<br />
| Tables_in_crib   |<br />
+------------------+<br />
| info_instances   |<br />
| info_object_size |<br />
| info_objects     |<br />
| info_privileges  |<br />
| info_users       |<br />
| version          |<br />
+------------------+<br />
6 rows in set (0.00 sec)<br />
</code><code><br />
mysql &gt; select * from version;<br />
+----+---------+---------------------+<br />
| ID | VERSION | UPDATED_TIMESTAMP   |<br />
+----+---------+---------------------+<br />
|  1 | 0.1     | 2010-12-09 16:24:05 |<br />
+----+---------+---------------------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
mysql &gt; select * from info_instances;<br />
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+<br />
| id | hostname                            | port | server_id | mysql_version | os              | os_version | architecture | bits | notes |<br />
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+<br />
|  1 | dolphin                             | 3331 |  14123561 | 5.1.50        | sun-solaris2.10 | 10         | sparc        |   64 | NULL  |<br />
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+<br />
1 row in set (0.00 sec)<br />
</code></p>
<p>From the above you realize you can identify all versions used in your setup, what hardware you are using, port numbers used and much more!</p>
<p>Lets see what users we have so far.<br />
<code><br />
mysql &gt; select * from info_users;<br />
+----+-------------+------------+---------------------------+-------------------------------------------+<br />
| id | instance_id | username   | hostname                  | password                                  |<br />
+----+-------------+------------+---------------------------+-------------------------------------------+<br />
|  1 |           1 | root       | localhost                 | *BA44AFCA02B64C198FAEB3043F47CA3797638975 |<br />
|  2 |           1 | root       | %.dev.domain.com          | *BA44AFCA02B64C198FAEB3043F47CA3797638975 |<br />
|  3 |           1 | root       | 127.0.0.1                 | *BA44AFCA02B64C198FAEB3043F47CA3797638975 |<br />
|  4 |           1 | abc        | %                         | *A4456E2A03EC0EE4E164BFA533443E82691DA163 |<br />
|  5 |           1 | def        | localhost                 | *5162BA4456B42A01FD8DDBB4CDBE46AFAD06C5AB |<br />
|  6 |           1 | ghi        | %                         | *95E6C48AFC85167C37A24130DD4F5FE0F48AB658 |<br />
|  7 |           1 | jkl        | %                         | *7A2D095E620E354F216EE00635E163406AD47392 |<br />
|  8 |           1 | mno        | %                         |                                           |<br />
|  9 |           1 | qpr        | localhost                 | *5162BA4456B42A01FD8DDBB4CDBE46AFAD06C5AB |<br />
+----+-------------+------------+---------------------------+-------------------------------------------+<br />
9 rows in set (0.00 sec)<br />
</code></p>
<p>If we had multiple machines set up as clients then we would have another group with instance_id 2, so on and so forth.</p>
<p>Remember this is an alpha tool and whatever you do with it is your responsibility. You are advised NOT TO set this up on production for now.</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26702&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26702&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/12/10/crib-%e2%80%93-central-information-base-for-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CRIB – CentRal Information Base for MySQL</title>
		<link>http://mysqlpreacher.com/wordpress/2010/12/crib-central-information-base-for-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=crib-%25e2%2580%2593-central-information-base-for-mysql-2</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/12/crib-central-information-base-for-mysql/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 11:19:50 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[big deployments]]></category>
		<category><![CDATA[crib]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=562</guid>
		<description><![CDATA[CRIB is a CentRal Information Base for MySQL, a long time coming project since I worked on it on and off for a few weeks and now I decided it&#8217;s time to hand it over to the global MySQL community.
So, what is CRIB?
CRIB is a central database which collects information about all your MySQL instances which you set as clients. It is monitoring in a way, but not the typical number of connections, memory, index usage, table scans, cpu usage and such, but rather consists of a repository where, if you have tens, hundreds or even thousands of clients, you can see where a particular user was created, where a certain database name features or which tables does a database consists of. It also features a script which logs table sizes periodically (customizable) so you can graph disk usage over time and be able to forecast future disk space requirements easily.
Download the latest code with: bzr branch lp:crib
First of all lets create the user used to write to the server (mother instance)

[dcassar@ubt]$ use5151
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 5.1.51 MySQL Community Server (GPL)


Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql &#62; grant create, insert, alter, update, delete, select, drop, execute, create temporary tables, create routine, alter routine, lock tables on crib.* to "mother"@"%" identified by "teacher";
Query OK, 0 rows affected (0.02 sec)


mysql &#62; exit
Bye
[dcassar@ubt]$

Lets go ahead and install CRIB on both server and client

[dcassar@ubt]$ cd INSTALL
[dcassar@ubt]$ ./crib_install.sh

brought to you by Darren Cassar

Anytime you need to cancel installation just press ( Ctrl + C )

Would you like to setup source and destination or just source?
1. Client and Server
2. New Client
Enter choice (default 2): 1
Installation starting

This section you'll supply the destination (CentRal Information Base) details

Enter CRIB user name (default root): mother
Enter CRIB password (default 'toor'):
Enter CRIB hostname (default localhost): 127.0.0.1
Enter CRIB port (default 3306): 5151

This section you'll supply the client details

Enter client user name (default root): dcassar
Enter client password (default 'toor'):
Enter client hostname (default localhost): dolphin
Enter client port (default 3306): 3331
Installation complete
[dcassar@ubt]$

Now is the time to gather the data from the clients and log it onto the server.

[dcassar@ubt]$ ./populate.sh CONFIG/crib_3331.cnf
[dcassar@ubt]$ ./tablesize.sh CONFIG/crib_3331.cnf

Lets log into the CRIB database on the mother server and see what details we have at our disposal.

[dcassar@ubt]$ use5151
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 5.1.51 MySQL Community Server (GPL)


Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql &#62; use crib
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql &#62; show tables;
+------------------+
&#124; Tables_in_crib   &#124;
+------------------+
&#124; info_instances   &#124;
&#124; info_object_size &#124;
&#124; info_objects     &#124;
&#124; info_privileges  &#124;
&#124; info_users       &#124;
&#124; version          &#124;
+------------------+
6 rows in set (0.00 sec)

mysql &#62; select * from version;
+----+---------+---------------------+
&#124; ID &#124; VERSION &#124; UPDATED_TIMESTAMP   &#124;
+----+---------+---------------------+
&#124;  1 &#124; 0.1     &#124; 2010-12-09 16:24:05 &#124;
+----+---------+---------------------+
1 row in set (0.00 sec)

mysql &#62; select * from info_instances;
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+
&#124; id &#124; hostname                            &#124; port &#124; server_id &#124; mysql_version &#124; os              &#124; os_version &#124; architecture &#124; bits &#124; notes &#124;
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+
&#124;  1 &#124; dolphin                             &#124; 3331 &#124;  14123561 &#124; 5.1.50        &#124; sun-solaris2.10 &#124; 10         &#124; sparc        &#124;   64 &#124; NULL  &#124;
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+
1 row in set (0.00 sec)

From the above you realize you can identify all versions used in your setup, what hardware you are using, port numbers used and much more!
Lets see what users we have so far.

mysql &#62; select * from info_users;
+----+-------------+------------+---------------------------+-------------------------------------------+
&#124; id &#124; instance_id &#124; username   &#124; hostname                  &#124; password                                  &#124;
+----+-------------+------------+---------------------------+-------------------------------------------+
&#124;  1 &#124;           1 &#124; root       &#124; localhost                 &#124; *BA44AFCA02B64C198FAEB3043F47CA3797638975 &#124;
&#124;  2 &#124;           1 &#124; root       &#124; %.dev.domain.com          &#124; *BA44AFCA02B64C198FAEB3043F47CA3797638975 &#124;
&#124;  3 &#124;           1 &#124; root       &#124; 127.0.0.1                 &#124; *BA44AFCA02B64C198FAEB3043F47CA3797638975 &#124;
&#124;  4 &#124;           1 &#124; abc        &#124; %                         &#124; *A4456E2A03EC0EE4E164BFA533443E82691DA163 &#124;
&#124;  5 &#124;           1 &#124; def        &#124; localhost                 &#124; *5162BA4456B42A01FD8DDBB4CDBE46AFAD06C5AB &#124;
&#124;  6 &#124;           1 &#124; ghi        &#124; %                         &#124; *95E6C48AFC85167C37A24130DD4F5FE0F48AB658 &#124;
&#124;  7 &#124;           1 &#124; jkl        &#124; %                         &#124; *7A2D095E620E354F216EE00635E163406AD47392 &#124;
&#124;  8 &#124;           1 &#124; mno        &#124; %                         &#124;                                           &#124;
&#124;  9 &#124;           1 &#124; qpr        &#124; localhost                 &#124; *5162BA4456B42A01FD8DDBB4CDBE46AFAD06C5AB &#124;
+----+-------------+------------+---------------------------+-------------------------------------------+
9 rows in set (0.00 sec)

If we had multiple machines set up as clients then we would have another group with instance_id 2, so on and so forth.
Remember this is an alpha tool and whatever you do with it is your responsibility. You are advised NOT TO set this up on production for now.]]></description>
			<content:encoded><![CDATA[<p>CRIB is a CentRal Information Base for MySQL, a long time coming project since I worked on it on and off for a few weeks and now I decided it&#8217;s time to hand it over to the global MySQL community.</p>
<p>So, what is CRIB?</p>
<p>CRIB is a central database which collects information about all your MySQL instances which you set as clients. It is monitoring in a way, but not the typical number of connections, memory, index usage, table scans, cpu usage and such, but rather consists of a repository where, if you have tens, hundreds or even thousands of clients, you can see where a particular user was created, where a certain database name features or which tables does a database consists of. It also features a script which logs table sizes periodically (customizable) so you can graph disk usage over time and be able to forecast future disk space requirements easily.</p>
<p>Download the latest code with: <b>bzr branch lp:crib</b></p>
<p>First of all lets create the user used to write to the server (mother instance)</p>
<p><code><br />
[dcassar@ubt]$ use5151<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 56<br />
Server version: 5.1.51 MySQL Community Server (GPL)<br />
</code><br />
<code><br />
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.<br />
This software comes with ABSOLUTELY NO WARRANTY. This is free software,<br />
and you are welcome to modify and redistribute it under the GPL v2 license<br />
</code><br />
<code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.<br />
</code><br />
<code><br />
mysql &gt; grant create, insert, alter, update, delete, select, drop, execute, create temporary tables, create routine, alter routine, lock tables on crib.* to "mother"@"%" identified by "teacher";<br />
Query OK, 0 rows affected (0.02 sec)<br />
</code><br />
<code><br />
mysql &gt; exit<br />
Bye<br />
[dcassar@ubt]$<br />
</code></p>
<p>Lets go ahead and install CRIB on both server and client</p>
<p><code><br />
[dcassar@ubt]$ cd INSTALL<br />
[dcassar@ubt]$ ./crib_install.sh<br />
</code><br />
<code>brought to you by Darren Cassar<br />
</code><code><br />
Anytime you need to cancel installation just press ( Ctrl + C )<br />
</code><code><br />
Would you like to setup source and destination or just source?<br />
1. Client and Server<br />
2. New Client<br />
Enter choice (default 2): 1<br />
Installation starting<br />
</code><br />
<code>This section you'll supply the destination (CentRal Information Base) details<br />
</code><br />
<code>Enter CRIB user name (default root): mother<br />
Enter CRIB password (default 'toor'):<br />
Enter CRIB hostname (default localhost): 127.0.0.1<br />
Enter CRIB port (default 3306): 5151<br />
</code><br />
<code>This section you'll supply the client details<br />
</code><br />
<code>Enter client user name (default root): dcassar<br />
Enter client password (default 'toor'):<br />
Enter client hostname (default localhost): dolphin<br />
Enter client port (default 3306): 3331<br />
Installation complete<br />
[dcassar@ubt]$<br />
</code><br />
Now is the time to gather the data from the clients and log it onto the server.</p>
<p><code><br />
[dcassar@ubt]$ ./populate.sh CONFIG/crib_3331.cnf<br />
[dcassar@ubt]$ ./tablesize.sh CONFIG/crib_3331.cnf<br />
</code></p>
<p>Lets log into the CRIB database on the mother server and see what details we have at our disposal.</p>
<p><code><br />
[dcassar@ubt]$ use5151<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 56<br />
Server version: 5.1.51 MySQL Community Server (GPL)<br />
</code><br />
<code><br />
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.<br />
This software comes with ABSOLUTELY NO WARRANTY. This is free software,<br />
and you are welcome to modify and redistribute it under the GPL v2 license<br />
</code><br />
<code><br />
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.<br />
</code><code><br />
mysql &gt; use crib<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; show tables;<br />
+------------------+<br />
| Tables_in_crib   |<br />
+------------------+<br />
| info_instances   |<br />
| info_object_size |<br />
| info_objects     |<br />
| info_privileges  |<br />
| info_users       |<br />
| version          |<br />
+------------------+<br />
6 rows in set (0.00 sec)<br />
</code><code><br />
mysql &gt; select * from version;<br />
+----+---------+---------------------+<br />
| ID | VERSION | UPDATED_TIMESTAMP   |<br />
+----+---------+---------------------+<br />
|  1 | 0.1     | 2010-12-09 16:24:05 |<br />
+----+---------+---------------------+<br />
1 row in set (0.00 sec)<br />
</code><code><br />
mysql &gt; select * from info_instances;<br />
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+<br />
| id | hostname                            | port | server_id | mysql_version | os              | os_version | architecture | bits | notes |<br />
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+<br />
|  1 | dolphin                             | 3331 |  14123561 | 5.1.50        | sun-solaris2.10 | 10         | sparc        |   64 | NULL  |<br />
+----+-------------------------------------+------+-----------+---------------+-----------------+------------+--------------+------+-------+<br />
1 row in set (0.00 sec)<br />
</code></p>
<p>From the above you realize you can identify all versions used in your setup, what hardware you are using, port numbers used and much more!</p>
<p>Lets see what users we have so far.<br />
<code><br />
mysql &gt; select * from info_users;<br />
+----+-------------+------------+---------------------------+-------------------------------------------+<br />
| id | instance_id | username   | hostname                  | password                                  |<br />
+----+-------------+------------+---------------------------+-------------------------------------------+<br />
|  1 |           1 | root       | localhost                 | *BA44AFCA02B64C198FAEB3043F47CA3797638975 |<br />
|  2 |           1 | root       | %.dev.domain.com          | *BA44AFCA02B64C198FAEB3043F47CA3797638975 |<br />
|  3 |           1 | root       | 127.0.0.1                 | *BA44AFCA02B64C198FAEB3043F47CA3797638975 |<br />
|  4 |           1 | abc        | %                         | *A4456E2A03EC0EE4E164BFA533443E82691DA163 |<br />
|  5 |           1 | def        | localhost                 | *5162BA4456B42A01FD8DDBB4CDBE46AFAD06C5AB |<br />
|  6 |           1 | ghi        | %                         | *95E6C48AFC85167C37A24130DD4F5FE0F48AB658 |<br />
|  7 |           1 | jkl        | %                         | *7A2D095E620E354F216EE00635E163406AD47392 |<br />
|  8 |           1 | mno        | %                         |                                           |<br />
|  9 |           1 | qpr        | localhost                 | *5162BA4456B42A01FD8DDBB4CDBE46AFAD06C5AB |<br />
+----+-------------+------------+---------------------------+-------------------------------------------+<br />
9 rows in set (0.00 sec)<br />
</code></p>
<p>If we had multiple machines set up as clients then we would have another group with instance_id 2, so on and so forth.</p>
<p>Remember this is an alpha tool and whatever you do with it is your responsibility. You are advised NOT TO set this up on production for now.</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26702&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26702&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/12/10/crib-%e2%80%93-central-information-base-for-mysql-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do you use MySQL replication? Do you use “FLUSH LOGS”? If yes you might want to read this.</title>
		<link>http://mysqlpreacher.com/wordpress/2010/08/do-you-use-mysql-replication-do-you-use-flush-logs-if-yes-you-might-want-to-read-this/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=do-you-use-mysql-replication-do-you-use-%25e2%2580%259cflush-logs%25e2%2580%259d-if-yes-you-might-want-to-read-this</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/08/do-you-use-mysql-replication-do-you-use-flush-logs-if-yes-you-might-want-to-read-this/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 18:12:22 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[binary log]]></category>
		<category><![CDATA[error log]]></category>
		<category><![CDATA[flush logs]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Replication]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=447</guid>
		<description><![CDATA[Scenario: Master-Master replication
Description: Master A is the active db server whilst Master B is a read only swappable db server hence both are creating binary logs. During backup I run &#8220;FLUSH LOGS&#8221; in order to have a simpler point in time recovery procedure if that case arises.
Problem: Flush logs is mean mean command :) &#8230;. it rotates not only my binary logs but my error log too (since I user error-log=blahblahblah in my my.cnf). Well given I flush logs every night my error log is cycled through every night, but unlike binary logs which have an incrimental number attached to the fine, error logs only have a `-log` attached to the filename and a second &#8220;FLUSH LOG&#8221; would just clear all error logs permanently. That is really not fun believe me!
So what is the solution? you could either:
1. Not use &#8220;FLUSH LOGS&#8221; (nah that aint happenin)
2. Not use &#8211;error-log (that aint happenin either cos I need to use it for my specific setup)
3. Create an ugly hack script which saves the error log or renames it or whatever (Ugly Ugly)
4. Create a variable in MySQL which says: flush-log-ignore-error-log which if set &#8220;FLUSH LOGS&#8221; will know not to mess around with my error log. Hence &#8230; create a feature request (nicer and friendlier solution) and submit a tested patch too whilst at it. 
If you think it is not idea that &#8220;FLUSH LOGS&#8221; recycles through error logs or and you have been bitten by the way it works like me, then feel free to put your vote into http://bugs.mysql.com/bug.php?id=56385&#38;thanks=sub so that MySQL sees the importance of it.
Because Sharing is Caring!]]></description>
			<content:encoded><![CDATA[<p>Scenario: Master-Master replication<br />
Description: Master A is the active db server whilst Master B is a read only swappable db server hence both are creating binary logs. During backup I run &#8220;FLUSH LOGS&#8221; in order to have a simpler point in time recovery procedure if that case arises.<br />
Problem: Flush logs is mean mean command :) &#8230;. it rotates not only my binary logs but my error log too (since I user error-log=blahblahblah in my my.cnf). Well given I flush logs every night my error log is cycled through every night, but unlike binary logs which have an incrimental number attached to the fine, error logs only have a `-log` attached to the filename and a second &#8220;FLUSH LOG&#8221; would just clear all error logs permanently. That is really not fun believe me!</p>
<p>So what is the solution? you could either:<br />
1. Not use &#8220;FLUSH LOGS&#8221; (nah that aint happenin)<br />
2. Not use &#8211;error-log (that aint happenin either cos I need to use it for my specific setup)<br />
3. Create an ugly hack script which saves the error log or renames it or whatever (Ugly Ugly)<br />
4. Create a variable in MySQL which says: flush-log-ignore-error-log which if set &#8220;FLUSH LOGS&#8221; will know not to mess around with my error log. Hence &#8230; create a feature request (nicer and friendlier solution) and submit a tested patch too whilst at it. </p>
<p>If you think it is not idea that &#8220;FLUSH LOGS&#8221; recycles through error logs or and you have been bitten by the way it works like me, then feel free to put your vote into <a href="http://bugs.mysql.com/bug.php?id=56385&amp;thanks=sub" >http://bugs.mysql.com/bug.php?id=56385&#038;thanks=sub</a> so that MySQL sees the importance of it.</p>
<p>Because Sharing is Caring!</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25728&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25728&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/08/31/do-you-use-mysql-replication-do-you-use-%e2%80%9cflush-logs%e2%80%9d-if-yes-you-might-want-to-read-this/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting a return code from a stored procedure</title>
		<link>http://mysqlpreacher.com/wordpress/2010/08/getting-a-return-code-from-a-stored-procedure/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-a-return-code-from-a-stored-procedure</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/08/getting-a-return-code-from-a-stored-procedure/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 06:00:20 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[stored procedure]]></category>
		<category><![CDATA[Stored Procedures]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=430</guid>
		<description><![CDATA[Sometimes we have some special need for a stored procedure to call another to do something. That is fine, but what if the second stored proc failed for some reason? Maybe you want to halt the first stored procedure (the caller) and not proceed with the work until the problem is verified and resolved. So How do you do it?
Simple, get a return code from the called procedure to determine if it worked or not!
Here&#8217;s a sample piece of code to explain better:

DROP PROCEDURE IF EXISTS `test`.`testing123`;
DELIMITER $$
CREATE
    PROCEDURE `test`.`testing123`(OUT a INT)
    BEGIN
        DECLARE EXIT HANDLER FOR SQLEXCEPTION
        BEGIN
          SET a=2;
        END;
        SET a=0;
# toggle the below as comment or not to see the call at the bottom working
# if you uncomment select abc you'll see the error, otherwise all is cool
#        select abc;
    END$$
DELIMITER ;
DROP PROCEDURE IF EXISTS `test`.`testing456`;
DELIMITER $$
CREATE
    PROCEDURE `test`.`testing456`()
    BEGIN
        SET @a=0;
        CALL `test`.`testing123` (@a);
        IF @a != 0 THEN
           SELECT "There is a problem with proc `testing123`";
        ELSE
           SELECT "Everything is cool";
        END IF;
    END$$
DELIMITER ;
CALL `test`.`testing456` ();

testing123 is the second stored proc in this case, called from testing456. The trick is to have an exit handler which returns a status number to the first stored proc (testing456). The latter will hold an if condition to do `something` depending on the return code received by testing123.
If you have any other suggestions I&#8217;d appreciate your input.]]></description>
			<content:encoded><![CDATA[<p>Sometimes we have some special need for a stored procedure to call another to do something. That is fine, but what if the second stored proc failed for some reason? Maybe you want to halt the first stored procedure (the caller) and not proceed with the work until the problem is verified and resolved. So How do you do it?</p>
<p>Simple, get a return code from the called procedure to determine if it worked or not!</p>
<p>Here&#8217;s a sample piece of code to explain better:</p>
<p><code><br />
DROP PROCEDURE IF EXISTS `test`.`testing123`;<br />
DELIMITER $$</p>
<p>CREATE<br />
    PROCEDURE `test`.`testing123`(OUT a INT)<br />
    BEGIN<br />
        DECLARE EXIT HANDLER FOR SQLEXCEPTION<br />
        BEGIN<br />
          SET a=2;<br />
        END;<br />
        SET a=0;</p>
<p># toggle the below as comment or not to see the call at the bottom working<br />
# if you uncomment select abc you'll see the error, otherwise all is cool</p>
<p>#        select abc;</p>
<p>    END$$</p>
<p>DELIMITER ;</p>
<p>DROP PROCEDURE IF EXISTS `test`.`testing456`;<br />
DELIMITER $$</p>
<p>CREATE<br />
    PROCEDURE `test`.`testing456`()<br />
    BEGIN<br />
        SET @a=0;<br />
        CALL `test`.`testing123` (@a);</p>
<p>        IF @a != 0 THEN<br />
           SELECT "There is a problem with proc `testing123`";<br />
        ELSE<br />
           SELECT "Everything is cool";<br />
        END IF;</p>
<p>    END$$</p>
<p>DELIMITER ;</p>
<p>CALL `test`.`testing456` ();<br />
</code></p>
<p>testing123 is the second stored proc in this case, called from testing456. The trick is to have an exit handler which returns a status number to the first stored proc (testing456). The latter will hold an if condition to do `something` depending on the return code received by testing123.</p>
<p>If you have any other suggestions I&#8217;d appreciate your input.</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25678&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25678&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/08/26/getting-a-return-code-from-a-stored-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Datetime &amp; Timestamp manipulation / migration explained</title>
		<link>http://mysqlpreacher.com/wordpress/2010/06/datetime-timestamp-manipulation-migration-explained/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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[datetime]]></category>
		<category><![CDATA[date_format]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[microsecond]]></category>
		<category><![CDATA[migrating to mysql]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[millisecond]]></category>
		<category><![CDATA[mysql]]></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 16 2008 09:12:51:893PM','%M %d %Y %h:%i:%s:%f%p'),'%Y%m%d%k%i%s.%f'); --&#62; 20080316211251.893000

Ok so this is just simple string manipulation where:
%M is the month name
%d is day number
%Y is the year
%h is the hour
%i is the minute
%s is the second
%f is the microsecond
%p is the period: ante or post meridiem
In the DATE_FORMAT part we se a %k which is in 24hr format in order to loose the period.
A more detailed list is found here
Here is a demo:
mysql Tue Jun 15 12:32:37 2010 &#62; CREATE TABLE test.abc(a DECIMAL(17,3)) ENGINE=MYISAM;
Query OK, 0 rows affected (0.03 sec)
mysql Tue Jun 15 12:32:45 2010 &#62; 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') );
Query OK, 1 row affected (0.01 sec)
mysql Tue Jun 15 12:32:51 2010 &#62; SELECT * FROM abc;
+--------------------+
&#124; a                  &#124;
+--------------------+
&#124; 20080316211251.893 &#124;
+--------------------+
1 row in set (0.00 sec)

mysql Tue Jun 15 12:32:56 2010 &#62; SELECT TIMESTAMP(a) FROM abc;
+----------------------------+
&#124; TIMESTAMP(a)               &#124;
+----------------------------+
&#124; 2008-03-16 21:12:51.893000 &#124;
+----------------------------+
1 row in set (0.00 sec)]]></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" >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><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25032&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25032&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/06/15/datetime-timestamp-manipulation-migration-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=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[access]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[expect]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Uncategorized]]></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 darren cassar
#mysqlpreacher.com
set machine  [lindex $argv 0]
set timeout -1
spawn ssh username@$machine
match_max 100000
expect -exact &#8220;assword: &#8221;
send &#8212; &#8220;password\r&#8221;
send &#8212; &#8220;sudo -k; sudo su &#8211; mysql\r&#8221;
expect -exact &#8220;sudo -k; sudo su &#8211; mysql&#8221;
expect -exact &#8220;assword:&#8221;
send &#8212; &#8220;password\r&#8221;
interact
# you should change the word password in &#8217;send &#8212; &#8220;password\r&#8221;&#8216; to your login password
# 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.
Create a bash script:
/path/to/login.sh
#!/bin/bash
#script by darren cassar
#mysqlpreacher.com
sm=&#8217;/path/to/sshmysql.exp&#8217;
menu() {
  echo &#8221; 101 &#8211; dev.databaseserver1 &#8221;
  echo &#8221; 102 &#8211; dev.databaseserver2 &#8221;
  echo &#8221; 103 &#8211; dev.databaseserver3 &#8221;
  echo &#8221; 201 &#8211; qa.databaseserver1 &#8221;
  echo &#8221; 301 &#8211; uat.databaseserver1 &#8221;
  echo &#8221; 302 &#8211; uat.databaseserver2 &#8221;
  echo &#8221; 401 &#8211; prod.databaseserver1 &#8221;
  echo &#8221; &#8221;
}
ARGUMENT=notmenu
if [ -z "$1" ]
  then
    ARGUMENT=menu
else
  choice=$1
fi
if [ $ARGUMENT = "menu" ]
  then
    menu
else
  case &#8220;$choice&#8221; in
  101&#124;dev.databaseserver1   ) $sm dev.databaseserver1;;
  102&#124;dev.databaseserver2   ) $sm dev.databaseserver2;;
  103&#124;dev.databaseserver3   ) $sm dev.databaseserver3;;
  201&#124;qa.databaseserver1   ) $sm qa.databaseserver1;;
  301&#124;uat.databaseserver1   ) $sm uat.databaseserver1;;
  302&#124;uat.databaseserver2   ) $sm uat.databaseserver2;;
  401&#124;prod.databaseserver1   ) $sm prod.databaseserver1;;
  *        ) echo &#8220;Wrong value passed to script&#8221;
             menu ;;
  esac
fi
alias l=&#8217;/path/to/login.sh&#8217;
Output: 
[darrencassar@mymachine ~ ]$ l
 101 &#8211; dev.databaseserver1
 102 &#8211; dev.databaseserver2
 103 &#8211; dev.databaseserver3
 201 &#8211; qa.databaseserver1
 301 &#8211; uat.databaseserver1
 302 &#8211; uat.databaseserver2
 401 &#8211; prod.databaseserver1
Output:
The below command would log you into the first development database server as mysql user.
[darrencassar@mymachine ~ ]$ l 101 
On each machine place aliases for each instance in the .profile
alias use3306=&#8217;mysql -u root -p -h 127.0.0.1 -P 3306 &#8211;prompt=&#8221;mysql \D&#62; &#8220;&#8216;
The above setup can be used using any client/server OS: Linux, Solaris, MAC OS or Windows(running Cygwin)
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 OpenSSL
Enjoy!]]></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" >OpenSSL</a></strong></p>
<p>Enjoy!</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23385&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23385&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/02/08/automating-mysql-access-with-expect-and-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Once upon a timestamp(milliseconds)….</title>
		<link>http://mysqlpreacher.com/wordpress/2009/08/once-upon-a-timestampmilliseconds/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=once-upon-a-timestampmilliseconds%25e2%2580%25a6</link>
		<comments>http://mysqlpreacher.com/wordpress/2009/08/once-upon-a-timestampmilliseconds/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 12:53:49 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[microsecond]]></category>
		<category><![CDATA[millisecond]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[timestamp]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=234</guid>
		<description><![CDATA[Once upon a time`stamp`, in a `data`base far far away, someone filed a bug named: `Microseconds precision is not retained by TIME, DATETIME, and TIMESTAMP field types.` &#8211; Bug Number 8523. This was the beginning of 2005, yet now that we are approaching the end of 2009, after 4.5 years, many (including myself) are still [...]]]></description>
			<content:encoded><![CDATA[Once upon a time`stamp`, in a `data`base far far away, someone filed a bug named: `Microseconds precision is not retained by TIME, DATETIME, and TIMESTAMP field types.` &#8211; Bug Number 8523. This was the beginning of 2005, yet now that we are approaching the end of 2009, after 4.5 years, many (including myself) are still [...]]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2009/08/06/once-upon-a-timestampmilliseconds%e2%80%a6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

