<?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; Intermediate</title>
	<atom:link href="http://mysqlpreacher.com/wordpress/category/databases/mysql/intermediate/feed/" rel="self" type="application/rss+xml" />
	<link>http://mysqlpreacher.com/wordpress</link>
	<description>Because Sharing is Caring</description>
	<lastBuildDate>Mon, 26 Sep 2011 23:34:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Recovering a MySQL `root` password &#8211; Three solutions</title>
		<link>http://mysqlpreacher.com/wordpress/2011/03/recovering-a-mysql-root-password-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:00:58 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[grants]]></category>
		<category><![CDATA[pass]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[skip-grant-tables]]></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 [...]]]></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 class="brush:shell">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>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2011/03/recovering-a-mysql-root-password-three-solutions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Could not find first log file name in binary log index file</title>
		<link>http://mysqlpreacher.com/wordpress/2010/12/could-not-find-first-log-file-name-in-binary-log-index-file/</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/12/could-not-find-first-log-file-name-in-binary-log-index-file/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 14:19:10 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[binlog]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[master-master]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=584</guid>
		<description><![CDATA[Scenario Master &#8211; Master replication MasterA is a client facing server MasterB is a warm standby server (read only) MasterB restarted abruptly and when instances were braught back up MasterA (it&#8217;s slave) was showing the following error: MasterA has the following error in show slave status: Last_IO_Errno: 1236 Last_IO_Error: Got fatal error 1236 from master [...]]]></description>
			<content:encoded><![CDATA[<p>Scenario Master &#8211; Master replication </p>
<p>MasterA is a client facing server<br />
MasterB is a warm standby server (read only)</p>
<p>MasterB restarted abruptly and when instances were braught back up MasterA (it&#8217;s slave) was showing the following error:</p>
<p>MasterA has the following error in show slave status:<br />
Last_IO_Errno: 1236<br />
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: &#8216;Could not find first log file name in binary log index file&#8217;</p>
<p>Solution:</p>
<p>Slave: stop slave;</p>
<p>Master: flush logs<br />
Master: show master status; &#8212; take note of the master log file and master log position</p>
<p>Slave: CHANGE MASTER TO MASTER_LOG_FILE=’log-bin.00000X′, MASTER_LOG_POS=106;<br />
Slave: start slave;</p>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2010/12/could-not-find-first-log-file-name-in-binary-log-index-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CRIB &#8211; CentRal Information Base for MySQL</title>
		<link>http://mysqlpreacher.com/wordpress/2010/12/crib-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[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[big deployments]]></category>
		<category><![CDATA[crib]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[monitoring]]></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 [...]]]></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>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2010/12/crib-central-information-base-for-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Do you use MySQL replication? Do you use &#8220;FLUSH LOGS&#8221;? 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/</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[Intermediate]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[binary log]]></category>
		<category><![CDATA[error log]]></category>
		<category><![CDATA[flush logs]]></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 [...]]]></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&#038;thanks=sub" target=_blank>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>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2010/08/do-you-use-mysql-replication-do-you-use-flush-logs-if-yes-you-might-want-to-read-this/feed/</wfw:commentRss>
		<slash:comments>6</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/</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[Uncategorized]]></category>
		<category><![CDATA[stored procedure]]></category>
		<category><![CDATA[stored procedures]]></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 [...]]]></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>
]]></content:encoded>
			<wfw:commentRss>http://mysqlpreacher.com/wordpress/2010/08/getting-a-return-code-from-a-stored-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

