<?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>Jason Fox &#187; mysql</title>
	<atom:link href="http://www.jasonfox.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jasonfox.com</link>
	<description>programming, products, and pontifications...</description>
	<lastBuildDate>Thu, 17 Jun 2010 02:29:42 +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>Installing MySQL with the InnoDB Plugin</title>
		<link>http://www.jasonfox.com/2010/03/installing-mysql-with-the-innodb-plugin/</link>
		<comments>http://www.jasonfox.com/2010/03/installing-mysql-with-the-innodb-plugin/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 23:48:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://www.jasonfox.com/?p=220</guid>
		<description><![CDATA[

I found after installing MySQL 5.1 that the “fast index creation”  feature is not utilized by the default InnoDB storage engine that comes  with MySQL 5.1.  This is the main reason why I went through the trouble  of installing  MySQL 5.1 in the first place.  :-/  However, have [...]]]></description>
			<content:encoded><![CDATA[<div id="OriginalPost">
<div>
<p>I found after installing MySQL 5.1 that the “fast index creation”  feature is not utilized by the default InnoDB storage engine that comes  with MySQL 5.1.  This is the main reason why I went through the trouble  of <a href="http://www.jasonfox.com/2010/03/installiing-and-running-mysql-5-1-next-to-5-0/">installing  MySQL 5.1 in the first place</a>.  :-/  However, have no fear, the <a href="http://www.innodb.com/products/innodb_plugin/features">InnoDB  plugin</a> is here!  (ok, that was lame, anyways…)</p>
<p>The InnoDB plugin is a replacement InnoDB storage engine developed  with the help of Sun, Google and Percona.  It supposedly provides better  overall performance compared with the default InnoDB storage engine  that comes with MySQL and it adds a few new features that I want such as  “fast index creation.”</p>
<p>If you’d like to try out the InnoDB plugin you’ll have to recompile  MySQL as a pre-compiled binary drop-in is not provided yet for OSX.  So, here are the steps for compiling and  installing MySQL 5.1 with the InnoDB plugin while maintaining a working  MySQL 5.0 installation on your computer.</p>
<ol>
<li>Download the <a href="http://dev.mysql.com/downloads/mysql/5.1.html#source">MySQL 5.1  source distribution</a> (v.5.1.43 for me; Change Platform to: Source  Code; Scroll down to the last distribution: Generic Linux (Architecture  Independent))</li>
<li>Download the <a href="http://www.innodb.com/products/innodb_plugin/download/">InnoDB  plugin source distribution</a> (v.1.0.6 for me)</li>
<li>Create a new install directory for MySQL 5.1: <code>sudo mkdir  /usr/local/mysql-5.1.43</code></li>
<li>Change ownership of the install directory to the mysql user: <code>sudo  chown -R mysql /usr/local/mysql-5.1.43</code></li>
<li>Extract the MySQL source: <code>tar -zxf mysql-5.1.43.tar.gz</code></li>
<li>Extract the InnoDB plugin source: <code>tar -zxf  innodb-1.0.6.tar.gz</code></li>
<li>Change into the MySQL source directory for storage engines: <code>cd  mysql-5.1.37/storage</code></li>
<li>Remove the version of the InnoDB plugin that MySQL comes with: <code>rm  -fr innobase</code></li>
<li>Replace the InnoDB plugin with the one you downloaded: <code>mv  innodb-1.0.6 innobase</code></li>
<li>Change into the MySQL source root: <code>cd ..</code></li>
<li>Create the make file: <code>./configure  --prefix=/usr/local/mysql-5.1.43 --with-extra-charsets=complex  --enable-thread-safe-client --enable-local-infile --enable-shared  --with-plugins=innobase --without-plugin-innodb_plugin  --with-federated-storage-engine</code>; note, I’m also including the <a href="http://dev.mysql.com/doc/refman/5.1/en/federated-storage-engine.html">Federated  Storage Engine</a> here in case you find a use for it in the future; <strong>NOTE</strong>: You will receive the following  warning, however, <a href="http://bugs.mysql.com/bug.php?id=42872">IT DID WORK</a>, so just ignore it:
<pre><code>configure: WARNING: unrecognized options: --without-plugin-innodb_plugin, --with-federated-storage-engine</code></pre>
</li>
<li>Compile MySQL: <code>make</code>; takes about 10 minutes or so</li>
<li>Install MySQL: <code>sudo make install</code></li>
<li>Change into your install directory: <code>cd  /usr/local/mysql-5.1.43</code></li>
<li>Create the MySQL database: <code>sudo ./bin/mysql_install_db  --user=mysql</code></li>
<li>Change ownership of the <code>var</code> directory to the mysql  user: <code>sudo chown -R mysql ./var</code></li>
</ol>
<h2>For more information see…</h2>
<p>If you get stuck you can check out the following resources that I  used to complete this process:</p>
<ul>
<li><a href="http://www.innodb.com/doc/innodb_plugin-1.0/innodb-plugin-installation.html#innodb-plugin-installation-source-unix">InnoDB  Plugin Installation Guide</a></li>
<li><a href="http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/">Installing  MySQL on OSX Snow Leopard</a> or the <a href="http://hivelogic.com/articles/installing-mysql-on-mac-os-x/">non-Snow  Leopard version</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.1/en/installing-source.html">MySQL  5.1 Installation Guide</a></li>
</ul>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonfox.com/2010/03/installing-mysql-with-the-innodb-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installiing and Running MySQL 5.1 and MySQL 5.0 simultaneously on Mac OS X</title>
		<link>http://www.jasonfox.com/2010/03/installiing-and-running-mysql-5-1-next-to-5-0/</link>
		<comments>http://www.jasonfox.com/2010/03/installiing-and-running-mysql-5-1-next-to-5-0/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 23:51:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://www.jasonfox.com/?p=223</guid>
		<description><![CDATA[

I am writing a few new applications and decided to upgrade to MySQL 5.1 from MySQL 5.0.  However, I have several legacy applications that still require MySQL 5.0.  So, I set out to get them both up and running side-by-side so I could forge a new path forward to 5.1 while not abandoning my 5.0 [...]]]></description>
			<content:encoded><![CDATA[<div id="OriginalPost">
<div>
<p>I am writing a few new applications and decided to upgrade to MySQL 5.1 from MySQL 5.0.  However, I have several legacy applications that still require MySQL 5.0.  So, I set out to get them both up and running side-by-side so I could forge a new path forward to 5.1 while not abandoning my 5.0 apps.</p>
<h2>Installing MySQL 5.1</h2>
<ol>
<li>Download the <strong>source</strong> distribution of the latest 5.1  (for me it was 5.1.42)</li>
<li>Decompress it and extract it into a directory</li>
<li>Create a new home for the 5.1 files, I put it in <code><strong>/usr/local/mysql-5.1.42</strong></code></li>
<li>Next <code>cd</code> into the directory where you extracted the  files</li>
<li>Run the following command substituting your install directory  created in step 3 above: <code>./configure --prefix=<strong>/usr/local/mysql-5.1.42</strong> --with-extra-charsets=complex --enable-thread-safe-client  --enable-local-infile --enable-shared --with-plugins=innobase</code></li>
<li>Compile the code by running: <code>make</code>; this will take a  few minutes (10ish?)</li>
<li>Install into your chosen directory with: <code>sudo make install</code></li>
<li>Next <code>cd</code> into your install directory: <code>cd <strong>/usr/local/mysql-5.1.42</strong></code></li>
<li>Create the mysql database with: <code>sudo ./bin/mysql_install_db  --user=mysql</code></li>
<li>Change ownership of the var directory (this is the data  directory): <code>sudo chown -R mysql ./var</code></li>
<li>Change ownership of the install directory: <code>sudo chown -R  mysql <strong>/usr/local/mysql-5.1.42</strong></code></li>
<li>Create a socket file in your install directory: <code>sudo -u  mysql touch mysql.sock</code>; mysql may create this itself on start-up,  but, I created it ahead of time</li>
<li>Start the server: <code>sudo -u mysql ./libexec/mysqld --basedir=<strong>/usr/local/mysql-5.1.42</strong> --port=6666 --socket=<strong>/usr/local/mysql-5.1.42/mysql.sock</strong> --user=mysql</code></li>
</ol>
<h2>Running MySQL 5.1 and 5.0</h2>
<ol>
<li>Edit your <code>my.cnf</code> file and explicitly add: <code>socket=/tmp/mysql.socket</code>;  if you do not do this when you start the 5.1 server the socket will be  deleted</li>
<li>Create a new <code>my.cnf</code> file in your 5.1 installation  root; for me: */usr/local/mysql-5.1.42/; your <code>my.cnf</code> file  should look like this:
<pre><code>    [mysqld]
    basedir=/usr/local/mysql-5.1.42/
    port=6666
    socket=/tmp/mysql.5.1.socket
    user=mysql
</code></pre>
</li>
<li>Change ownership of the <code>my.cnf</code> file to the <code>mysql</code> user: <code>sudo chown -R mysql my.cnf</code></li>
<li>Create a plist file for <code>launchd</code> called something  like: <code>com.mysql.mysqld.5.1.plist</code> in <code>/Library/LaunchDaemons</code>;  your plist file should look like this:
<pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
    &lt;plist version="1.0"&gt;
        &lt;dict&gt;
            &lt;key&gt;KeepAlive&lt;/key&gt;
            &lt;true /&gt;
            &lt;key&gt;Label&lt;/key&gt;
            &lt;string&gt;com.mysql.mysqld.5.1&lt;/string&gt;
            &lt;key&gt;ProgramArguments&lt;/key&gt;
            &lt;array&gt;
                &lt;string&gt;/usr/local/mysql-5.1.42/bin/mysqld_safe&lt;/string&gt;
                &lt;string&gt;--defaults-file=/usr/local/mysql-5.1.42/my.cnf&lt;/string&gt;
            &lt;/array&gt;
            &lt;key&gt;RunAtLoad&lt;/key&gt;
            &lt;true /&gt;
            &lt;key&gt;UserName&lt;/key&gt;
            &lt;string&gt;mysql&lt;/string&gt;
            &lt;key&gt;WorkingDirectory&lt;/key&gt;
            &lt;string&gt;/usr/local/mysql-5.1.42&lt;/string&gt;
        &lt;/dict&gt;
    &lt;/plist&gt;
</code></pre>
</li>
<li>Change ownership of the plist file to root like so: <code>sudo  chown root /Library/LaunchDaemons/com.mysql.mysqld.5.1.plist</code></li>
<li>Test it out by launching mysql: <code>sudo launchctl load -w  /Library/LaunchDaemons/com.mysql.mysqld.5.1.plist</code>; The next time  you start up both MySQL 5.0 and 5.1 should be started up.  Check the <code>/tmp</code> directory after start-up to ensure both sockets were created  successfully.</li>
</ol>
<h2>A few notes about this process</h2>
<ul>
<li>When you install from source the layout of the installation is  different than when you install from the binary distribution, i.e., the  data direectory is <code>var</code> not <code>data</code> and the server  binary is in <code>libexec</code> not <code>bin</code>, etc. For more  information check out <a href="http://dev.mysql.com/doc/refman/5.1/en/installation-layouts.html">this  article</a>.</li>
<li>When starting a second instance of mysqld you must specify  different values for the following options: <code>port</code>, <code>socket</code>,  <code>pid-file</code>, <code>tmpdir</code>, <code>datadir</code>.   However, if you specify the <code>basedir</code> you only need to  explicitly set values for <code>socket</code> and <code>port</code> as  we did in the last step above.  For more information check out <a href="http://dev.mysql.com/doc/refman/5.1/en/multiple-servers.html">this  article</a>.</li>
<li>When you start the mysql client you must specify the socket and  port like so: <code>/usr/local/mysql-5.1.42/bin/mysql -P 6666 -S  /usr/local/mysql-5.1.42/mysql.sock -u root</code>; Alternatively you can  create a hidden <code>.my.cnf</code> file in your home directory and  specify which server should be connected to by default when you run the  mysql client.  Your <code>.my.cnf</code> file should look like this:
<pre><code>    [client]
    port=6666
    socket=/tmp/mysql.5.1.socket
</code></pre>
</li>
</ul>
<h2><strong>Working with Rails</strong></h2>
<div>Now that you have two MySQL  servers running  you need to tell Rails which one you want to use in a  more explicit  fashion.  Here’s an example from my <code>database.yml</code> file:</div>
<pre><code>    # Main database connection for the media_service;
    # Uses MySQL 5.1
    development:
      adapter: mysql
      encoding: utf8
      database: my_development
      username: foo
      password: bar
      socket: /tmp/mysql.5.1.socket
      port: 6666</code></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonfox.com/2010/03/installiing-and-running-mysql-5-1-next-to-5-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL Allows NULLs Where They Are Not Welcome</title>
		<link>http://www.jasonfox.com/2009/02/mysql-allows-nulls-where-they-are-not-allowed/</link>
		<comments>http://www.jasonfox.com/2009/02/mysql-allows-nulls-where-they-are-not-allowed/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 18:18:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.jasonfox.com/?p=94</guid>
		<description><![CDATA[I recently came across an annoying bug in MySQL v5.1 (also in 6.0 apparently) that bit me hard, so, I thought I&#8217;d post on it in case you are being bitten by the same bug.
If you attempt to update a column that does not allow NULL to NULL, MySQL will set the column&#8217;s value to [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across an annoying bug in MySQL v5.1 (also in 6.0 apparently) that bit me hard, so, I thought I&#8217;d post on it in case you are being bitten by the same bug.</p>
<p>If you attempt to update a column that does not allow NULL to NULL, MySQL will set the column&#8217;s value to the default value for that column&#8217;s data type.  This is true only when you are not running MySQL <a href="http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_trans_tables">strict mode</a>.  Here&#8217;s an example to illustrate.</p>
<pre>mysql&gt; create table null_test (id int not null unique(id), name varchar(25)
null default null);
Query OK, 0 rows affected (0.01 sec)

mysql&gt; show create table null_test;
+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table     | Create Table                                                                                                                                           |
+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| null_test | CREATE TABLE `null_test` (
  `id` int(11) NOT NULL,
  `name` varchar(25) default NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+-----------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql&gt; insert into null_test (id, name) values (1, 'Jane');
Query OK, 1 row affected (0.00 sec)

mysql&gt; update null_test set id = null;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql&gt; select * from null_test where name = 'Jane';
+----+------+
| id | name |
+----+------+
|  0 | Jane |
+----+------+
1 row in set (0.00 sec)</pre>
<p>More information about this bug can be found in the <a href="http://bugs.mysql.com/bug.php?id=33699">bug report</a> submitted Janurary 4, 2008.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonfox.com/2009/02/mysql-allows-nulls-where-they-are-not-allowed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check Constraints and MySQL</title>
		<link>http://www.jasonfox.com/2009/02/check-constraints-and-mysql/</link>
		<comments>http://www.jasonfox.com/2009/02/check-constraints-and-mysql/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 00:47:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://www.jasonfox.com/?p=80</guid>
		<description><![CDATA[Unfortunately, MySQL does not support check constraints out of the box.  This makes the task of enforcing business logic in the database layer difficult, but not impossible.  ]]></description>
			<content:encoded><![CDATA[<div class="discussion">
<p class="description">Unfortunately, MySQL does not support <a href="http://en.wikipedia.org/wiki/Check_Constraint">check constraints</a> out of the box.  This makes the task of enforcing business logic in the database layer difficult, but not impossible.  I recently found <a href="http://forge.mysql.com/wiki/Triggers#Emulating_Check_Constraints">this approach</a> to implementing check constraints in MySQL.  It&#8217;s not as pretty and clean as I&#8217;d like, but, it&#8217;s the best approach that I&#8217;ve found so far.</p>
<p>Now. why would you want to encode business logic in the database?  Can&#8217;t you make due with your <a href="http://api.rubyonrails.com/classes/ActiveRecord/Validations.html">ActiveRecord::Validations</a>?</p>
<p>Well, have you ever updated the database directly?  Have you ever called update_attribute on an object?  How about save_with_validation(false)?   Yeah, I thought so.  Read more about why you should treat your database as a fortress in <a href="http://blog.chak.org/">Dan Chak</a>&#8217;s recently released book, <a href="http://www.amazon.com/Enterprise-Rails-Dan-Chak/dp/0596515200/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1233881182&amp;sr=8-1">Enterprise Rails</a> (review coming soon).</div>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonfox.com/2009/02/check-constraints-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
