<?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>boolean.co.nz &#187; MySQL</title>
	<atom:link href="http://boolean.co.nz/blog/category/development/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://boolean.co.nz/blog</link>
	<description>Where there is more to logic than TRUE or FALSE</description>
	<lastBuildDate>Fri, 18 May 2012 09:56:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>MySQL datatype for storing IP addresses</title>
		<link>http://boolean.co.nz/blog/mysql-datatype-for-storing-ip-addresses/782/</link>
		<comments>http://boolean.co.nz/blog/mysql-datatype-for-storing-ip-addresses/782/#comments</comments>
		<pubDate>Fri, 18 May 2012 09:56:24 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=782</guid>
		<description><![CDATA[The best way to store a (version 4) IP address in a MySQL database is as an integer. This may sound strange but MySQL has two powerful functions to enable you to store an IP address as an unsigned INT. Searching an integer is much faster than searching a string and additionally integers take up [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" /></td>
</tr>
</table>
<p>The best way to store a (version 4) IP address in a MySQL database is as an integer. This may sound strange but MySQL has two powerful <a href="http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html" title="functions" target="_blank">functions</a> to enable you to store an IP address as an <em>unsigned</em> INT. Searching an integer is much faster than searching a string and additionally integers take up less storage space which is great when working with large datasets.</p>
<div class="codesnip-container" >mysql> SELECT INET_ATON(&#8217;10.0.5.9&#8242;);<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
INET_ATON(&#8217;10.0.5.9&#8242;)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
167773449<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
1 row in set (0.00 sec)</div>
<p>and the reverse function</p>
<div class="codesnip-container" >mysql> SELECT INET_NTOA(167773449);<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
INET_NTOA(167773449)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
10.0.5.9<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
1 row in set (0.00 sec)</div>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/mysql-datatype-for-storing-ip-addresses/782/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL zerofill for numerical types</title>
		<link>http://boolean.co.nz/blog/mysql-zerofill-numerical-types/742/</link>
		<comments>http://boolean.co.nz/blog/mysql-zerofill-numerical-types/742/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 19:36:39 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=742</guid>
		<description><![CDATA[MySQL has a feature for numerical types known as zerofill which effects the display size of numerical types. Unlike string types, the number inside the parentheses is not the storage size in characters for the type. For numerical types the type name itself solely determines storage size. Column Type Bytes On Disk Signed Storage Range [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" />
<td></tr>
</table>
<p>MySQL has a feature for <a href="http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html" title="numerical" target="_blank">numerical</a> types known as zerofill which effects the display size of numerical types. Unlike <a href="http://boolean.co.nz/blog/max-length-for-mysql-text-field-types/135/" title="string types" target="_blank">string types</a>, the number inside the parentheses is <em>not</em> the storage size in characters for the type. For numerical types the type name itself solely determines storage size.</p>
<table>
<tr>
<td><strong>Column Type</strong></td>
<td><strong>Bytes On Disk</strong></td>
<td><strong>Signed Storage Range</strong></td>
<td><strong>Unsigned Storage Range</strong></td>
</tr>
<tr>
<td>tinyint</td>
<td>1 byte</td>
<td>-128 to 127</td>
<td>0 to 255</td>
</tr>
<tr>
<td>smallint</td>
<td>2 bytes</td>
<td>-32768 to 32767</td>
<td>0 to 65535</td>
</tr>
<tr>
<td>mediumint</td>
<td>3 bytes</td>
<td>-8388608 to 8388607</td>
<td>0 to 16777215</td>
</tr>
<tr>
<td>int</td>
<td>4 bytes</td>
<td>-2147483648 to 2147483647</td>
<td>0 to 4294967295</td>
</tr>
<tr>
<td>bigint</td>
<td>8 bytes</td>
<td>-9223372036854775808 to 9223372036854775807</td>
<td>0 to 18446744073709551615</td>
</tr>
</table>
<p>So zerofill with default width &#8211; the same as int(10):</p>
<div class="codesnip-container" >mysql> create table test_table (t int zerofill);<br />
Query OK, 0 rows affected (0.02 sec)</p>
<p>mysql> insert into test_table set t = 10;<br />
Query OK, 1 row affected (0.02 sec)</p>
<p>mysql> select * from test_table;<br />
+————+<br />
| t |<br />
+————+<br />
| 0000000010 |<br />
+————+<br />
1 row in set (0.08 sec)</p></div>
<p>And without zerofill:</p>
<div class="codesnip-container" >mysql> create table test_table (t int);<br />
Query OK, 0 rows affected (0.01 sec)</p>
<p>mysql> insert into test_table set t = 10;<br />
Query OK, 1 row affected (0.01 sec)</p>
<p>mysql> select * from test_table;<br />
+——+<br />
| t |<br />
+——+<br />
| 10 |<br />
+——+<br />
1 row in set (0.01 sec)</p></div>
<p>A common usage for is creating invoice ids such as INV00000945.</p>
<p><strong>Notes:</strong><br />
If you do not have zerofill specified there is no difference between int(3) and int(10)<br />
When doing comparisons: if compared as integers then the values are the same; if you compare as strings the values are different.</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/mysql-zerofill-numerical-types/742/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL not starting in MAMP OSX</title>
		<link>http://boolean.co.nz/blog/mysql-not-starting-mamp/721/</link>
		<comments>http://boolean.co.nz/blog/mysql-not-starting-mamp/721/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 00:32:03 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OSX]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=721</guid>
		<description><![CDATA[Sometimes MySQL doesn&#8217;t come up again when attempting to start MAMP, &#8211; it just hangs after starting Apache. If you don&#8217;t want to have to reboot (and shutting down and restarting MAMP hasn&#8217;t helped) then quit MAMP, open a Terminal window and type: ps aux &#124; grep mysql lsof -i killall -9 mysqld]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" /></td>
</tr>
</table>
<p>Sometimes MySQL doesn&#8217;t come up again when attempting to start MAMP, &#8211; it just hangs after starting Apache. If you don&#8217;t want to have to reboot (and shutting down and restarting MAMP hasn&#8217;t helped) then quit MAMP, open a Terminal window and type:</p>
<div class="codesnip-container" >ps aux | grep mysql<br />
lsof -i<br />
killall -9 mysqld</div>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/mysql-not-starting-mamp/721/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find the size of all databases on a server</title>
		<link>http://boolean.co.nz/blog/find-the-size-of-all-databases-on-a-server/604/</link>
		<comments>http://boolean.co.nz/blog/find-the-size-of-all-databases-on-a-server/604/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 11:49:33 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=604</guid>
		<description><![CDATA[A quick way to create a view to show file size statistics across databases on a server. DROP VIEW IF EXISTS alldb; CREATE VIEW AllDatabases AS SELECT s.schema_name AS &#8216;Schema&#8217;, SUM (t.data_length) AS Data, SUM ( t.index_length ) AS Indexes, SUM (t.data_length) + SUM (t.index_length) AS &#8216;Mb Used&#8217;, IF (SUM(t.data_free)=0,&#8221;,SUM (t.data_free)) As &#8216;Mb Free&#8217;, IF [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" /></td>
</tr>
</table>
<p>A quick way to create a view to show file size statistics across databases on a server.</p>
<div class="codesnip-container" >DROP VIEW IF EXISTS alldb;<br />
CREATE VIEW AllDatabases AS<br />
SELECT<br />
s.schema_name AS &#8216;Schema&#8217;,<br />
SUM (t.data_length) AS Data,<br />
SUM ( t.index_length ) AS Indexes,<br />
SUM (t.data_length) + SUM (t.index_length) AS &#8216;Mb Used&#8217;,<br />
IF (SUM(t.data_free)=0,&#8221;,SUM (t.data_free)) As &#8216;Mb Free&#8217;,<br />
IF (SUM(t.data_free)=0,&#8221;, 100 * (SUM (t.data_length) + SUM (t.index_length)) / ((SUM (t.data_length)+SUM (t.index_length) + SUM (IFNULL(t.data_free,0))) ) ) AS &#8216;Pct Used&#8217;, COUNT (table_name) AS Tables<br />
FROM information_schema.schemata s<br />
LEFT JOIN information_schema.tables t ON s.schema_name = t.table_schema<br />
GROUP BY s.schema_name<br />
WITH ROLLUP</div>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/find-the-size-of-all-databases-on-a-server/604/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exporting a MySQL Database Schema as XML</title>
		<link>http://boolean.co.nz/blog/exporting-a-mysql-database-schema-as-xml/354/</link>
		<comments>http://boolean.co.nz/blog/exporting-a-mysql-database-schema-as-xml/354/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 10:10:12 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=354</guid>
		<description><![CDATA[Dumping a database schema is a an often required quick task. This script will read the schema from a MySQL database, and output it XML to describe it. &#60;?php // Define a few constants define(&#8220;DB_SERVER&#8221;, &#8220;localhost&#8221;); define(&#8220;DB_USER&#8221;, &#8220;root&#8221;); define(&#8220;DB_PASS&#8221;, &#8220;password&#8221;); define(&#8220;DB_NAME&#8221;, &#8220;example&#8221;); // Lets connect to the db $dbhandle = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(&#8220;Unable [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" /></td>
</tr>
</table>
<p>Dumping a database schema is a an often required quick task. This script will read the schema from a MySQL database, and output it XML to describe it.</p>
<div class="codesnip-container" >&lt;?php<br />
// Define a few constants<br />
define(&#8220;DB_SERVER&#8221;, &#8220;localhost&#8221;);<br />
define(&#8220;DB_USER&#8221;, &#8220;root&#8221;);<br />
define(&#8220;DB_PASS&#8221;, &#8220;password&#8221;);<br />
define(&#8220;DB_NAME&#8221;, &#8220;example&#8221;);</p>
<p>// Lets connect to the db<br />
$dbhandle = mysql_connect(DB_SERVER, DB_USER, DB_PASS)<br />
   or die(&#8220;Unable to connect to MySQL&#8221;); </p>
<p>// Choose a database to work with<br />
$selected = mysql_select_db(DB_NAME, $dbhandle)<br />
   or die(&#8220;Could not select examples&#8221;);<br />
// Return all of the available tables<br />
$result_tbl = mysql_query( &#8220;SHOW TABLES FROM &#8220;.DB_NAME, $dbhandle ); </p>
<p>$tables = array();<br />
while ($row = mysql_fetch_row($result_tbl)) {<br />
   $tables[] = $row[0];<br />
} </p>
<p>$output = &#8220;&lt;?xml version=\&#8221;1.0\&#8221; ?&gt;\n&#8221;;<br />
$output .= &#8220;&lt;schema&gt;&#8221;; </p>
<p>// Now iterate through each table and return the fields<br />
foreach ( $tables as $table ) {<br />
   $output .= &#8220;&lt;table name=\&#8221;$table\&#8221;&gt;&#8221;;<br />
   $result_fld = mysql_query( &#8220;SHOW FIELDS FROM &#8220;.$table, $dbhandle ); </p>
<p>   while( $row1 = mysql_fetch_row($result_fld) ) {<br />
      $output .= &#8220;&lt;field name=\&#8221;$row1[0]\&#8221; type=\&#8221;$row1[1]\&#8221;";<br />
      $output .= ($row1[3] == &#8220;PRI&#8221;) ? &#8221; primary_key=\&#8221;yes\&#8221; /&gt;&#8221; : &#8221; /&gt;&#8221;;<br />
   } </p>
<p>   $output .= &#8220;&lt;/table&gt;&#8221;;<br />
} </p>
<p>$output .= &#8220;&lt;/schema&gt;&#8221;; </p>
<p>// Notify the browser the type of file being dealt with<br />
header(&#8220;Content-type: text/xml&#8221;);<br />
// Display the XML to describe the schema<br />
echo $output; </p>
<p>// Dont forget to close the connection<br />
mysql_close($dbhandle);<br />
?&gt;</p></div>
<p>Remember, this is an example, and real world code should escape characters, follow best security practices etc. Proof of concept code here, &#8211; not a snippet to put live.</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/exporting-a-mysql-database-schema-as-xml/354/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scheduling mySQL backups</title>
		<link>http://boolean.co.nz/blog/scheduling-mysql-backups/316/</link>
		<comments>http://boolean.co.nz/blog/scheduling-mysql-backups/316/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 02:31:55 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=316</guid>
		<description><![CDATA[I&#8217;m sure there is no need to explain the virtues of regular backups. Below are three steps to peace of mind 1) Configure a backup directory on the server mkdir /var/lib/backupfolder cd /var/lib/backupfolder 2) Make a backup script vi mysqlbackup.sh #!/bin/sh # MySQL server username goes here USERNAME=&#8221;username&#8221; # MySQL server password goes here PASSWORD=&#8221;password&#8221; [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" />
</td>
</tr>
</table>
<p>I&#8217;m sure there is no need to explain the virtues of regular backups. Below are three steps to peace of mind</p>
<p>1) Configure a backup directory on the server</p>
<div class="codesnip-container" >mkdir /var/lib/backupfolder<br />
cd /var/lib/backupfolder</div>
<p>2) Make a backup script</p>
<div class="codesnip-container" >vi mysqlbackup.sh</div>
<div class="codesnip-container" >#!/bin/sh<br />
# MySQL server username goes here<br />
USERNAME=&#8221;username&#8221;<br />
# MySQL server password goes here<br />
PASSWORD=&#8221;password&#8221;<br />
# List of DBNAMES for Backup<br />
DBNAME=&#8221;dbname&#8221;<br />
#date timestamp used in the log<br />
DATE=`/bin/date +%Y-%m-%d_%Hh%Mm`<br />
# format the output file<br />
OUTDIR=&#8221;/var/lib/backupfolder/&#8221;<br />
OUTFILE=&#8221;ip_bindass&#8221;.$DATE.&#8221;sql.gz&#8221;<br />
#working directory<br />
DIR=&#8221;/var/lib/backupfolder/&#8221;<br />
#cd $DIR<br />
# Do the MySQL Backup<br />
/usr/bin/mysqldump &#8211;database $DBNAME &#8211;opt &#8211;single-transaction -u$USERNAME -p$PASSWORD | /usr/bin/gzip -9 > $OUTDIR$OUTFILE</div>
<p>Dont forget to change permissions</p>
<div class="codesnip-container" >chmod +x mysqlbackup.sh</div>
<p>3) Schedule the backup in crontab</p>
<div class="codesnip-container" >crontab -e</div>
<p>Add something along the lines of:</p>
<div class="codesnip-container" >30 23 * * * /var/lib/backupfolder/mysqlbackup.sh</div>
<p>To backup at 11:30PM every day. Just as important as to backup up is to test restores; &#8211; it&#8217;s no good having backups and feeling at ease if you cant recover in the event of catastrophe!</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/scheduling-mysql-backups/316/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Help keep the internet free</title>
		<link>http://boolean.co.nz/blog/help-keep-the-internet-free/247/</link>
		<comments>http://boolean.co.nz/blog/help-keep-the-internet-free/247/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 21:44:48 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=247</guid>
		<description><![CDATA[A big part of the Internet is built on LAMP (Linux, Apache, MySQL and PHP/Perl/Python). Now Oracle is trying to buy Sun, which owns MySQL. It&#8217;s not in the Internet users interest that one key piece of the net would be owned by an entity that has more to gain by severely limiting and in [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="mysql_logo" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" />
</td>
</tr>
</table>
<p>A big part of the Internet is built on LAMP (Linux, Apache, MySQL and PHP/Perl/Python). Now Oracle is trying to buy Sun, which owns MySQL.</p>
<p>It&#8217;s not in the Internet users interest that one key piece of the net would be owned by an entity that has more to gain by severely limiting and in the long run even killing it as an open source product than by keeping it alive. If Oracle were allowed to acquire MySQL, we would be looking at less competition among databases, which will mean higher license and support prices. In the end it&#8217;s always the consumers and the small businesses that have to pay the bills, in this case to Oracle.</p>
<p>Read on <a href="http://monty-says.blogspot.com/2009/12/help-keep-internet-free.html">here</a> at Monty&#8217;s blog (creator of MySQL) or head <a href="http://www.helpmysql.org">here</a> for the official website.</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/help-keep-the-internet-free/247/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using LIMIT when querying a single row</title>
		<link>http://boolean.co.nz/blog/using-limit-when-querying-a-single-row/239/</link>
		<comments>http://boolean.co.nz/blog/using-limit-when-querying-a-single-row/239/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 13:49:07 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=239</guid>
		<description><![CDATA[Sometimes you know you are only looking for one row when you are querying your tables. It may be that you are fetching a unique record or checking the existence of any number of records that satisfy your WHERE clause. Adding LIMIT 1 to your query can increase performance in this situation; &#8211; the database [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="mysql_logo" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" />
</td>
</tr>
</table>
<p>Sometimes you know you are only looking for one row when you are querying your tables.  It may be that you are fetching a unique record or checking the existence of any number of records that satisfy your WHERE clause.</p>
<p>Adding LIMIT 1 to your query can increase performance in this situation; &#8211; the database engine will stop scanning for records after it finds just one, instead of going through the whole table or index.</p>
<p>For example:</p>
<div class="codesnip-container" >$record = mysql_query(&#8220;SELECT username FROM user WHERE country = &#8216;UK&#8217;&#8221;);<br />
if (mysql_num_rows($record) > 0) {<br />
// &#8230;<br />
}</div>
<p>Can become:</p>
<div class="codesnip-container" >$record = mysql_query(&#8220;SELECT username FROM user WHERE country = &#8216;UK&#8217; LIMIT 1&#8243;);<br />
if (mysql_num_rows($record) > 0) {<br />
 // &#8230;<br />
}</div>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/using-limit-when-querying-a-single-row/239/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maxlength for MySQL TEXT field types</title>
		<link>http://boolean.co.nz/blog/max-length-for-mysql-text-field-types/135/</link>
		<comments>http://boolean.co.nz/blog/max-length-for-mysql-text-field-types/135/#comments</comments>
		<pubDate>Fri, 08 May 2009 08:33:56 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=135</guid>
		<description><![CDATA[MySQL supports four TEXT field types (TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT) MyISAM tables in MySQL have a maximum row size 65,535 bytes and all the data in a row must fit within that limit. Luckily however TEXT field types are stored outside of the table itself and thus only contribute 9 &#8211; 12 bytes towards [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>
<img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="mysql_logo" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" />
</td>
</tr>
</table>
<p><strong>MySQL supports four TEXT field types (TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT)</strong></p>
<p>MyISAM tables in MySQL have a maximum row size 65,535 bytes and <em>all</em> the data in a row must fit within that limit.</p>
<p>Luckily however TEXT field types are stored outside of the table itself and thus only contribute 9 &#8211; 12 bytes towards that limit.</p>
<p>Further reading is <a href="http://dev.mysql.com/doc/refman/5.1/en/storage-requirements.html">here.</a></p>
<p>Because TEXT data types are able to store so much more data than VARCHAR and CHAR field types it makes sense to use them when storing web pages or similar content in the database.</p>
<p>The maximum amount of data that can be stored for each data type is approximately:</p>
<p>TINYTEXT 256 bytes<br />
TEXT 65,535 bytes ~64kb<br />
MEDIUMTEXT  16,777,215 bytes ~16MB<br />
LONGTEXT 4,294,967,295 bytes ~4GB </p>
<p>So most of the time TEXT will suffice, but if you are scratch building a CMS it might be an idea to think about MEDIUMTEXT</p>
<p><em>Update: (20/05/201) &#8211; I see a lot of hits on this page, so I thought I&#8217;d spell out the information here for the terms you seem to be searching for&#8230;</em></p>
<p><strong>TINYTEXT</strong> is a string data type that can store up to to 255 characters. </p>
<p><strong>TEXT</strong> is a string data type that can store up to 65,535 characters. TEXT is commonly used for storing blocks of text used for brief articles. </p>
<p><strong>LONGTEXT</strong> is a string data type with a maximum length of 4,294,967,295 characters. Use LONGTEXT if you need to store large blocks of text, such as a chapter of a book.  </p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/max-length-for-mysql-text-field-types/135/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL date_format</title>
		<link>http://boolean.co.nz/blog/mysql-date_format/118/</link>
		<comments>http://boolean.co.nz/blog/mysql-date_format/118/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 16:48:56 +0000</pubDate>
		<dc:creator>Boolean</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://boolean.co.nz/blog/?p=118</guid>
		<description><![CDATA[I always seem to be digging around to find MySQL&#8217;s date formatting syntax, so here is a couple of common conversions&#8230; select date_format(date, &#8216;%d %M %Y&#8217;) as new_date from tablename where date is the name of your date field, and new_date is the variable name which you can use to reference the value. date_format String [...]]]></description>
			<content:encoded><![CDATA[<table></tr>
<td>
<img src="http://boolean.co.nz/blog/wp-content/uploads/2009/04/mysql_logo.png" alt="mysql_logo" title="mysql_logo" width="204" height="106" class="aligncenter size-full wp-image-96" />
</td>
</tr>
</table>
<p>I always seem to be digging around to find MySQL&#8217;s date formatting syntax, so here is a couple of common conversions&#8230;</p>
<div class="codesnip-container" >select date_format(date, &#8216;%d %M %Y&#8217;) as new_date from tablename</div>
<p>where <strong>date</strong> is the name of your date field, and <strong>new_date </strong>is the variable name which you can use to reference the value.</p>
<table>
<tr>
<td><strong>date_format String</strong></td>
<td><strong>Example</strong></td>
</tr>
<tr>
<td>&#8216;%e/%c/%Y&#8217;</td>
<td> 25/4/2009 </td>
</tr>
<tr>
<td>&#8216;%c/%e/%Y&#8217;</td>
<td>4/25/2009</td>
</tr>
<tr>
<td>&#8216;%d/%m/%Y&#8217;</td>
<td>25/04/2009</td>
</tr>
<tr>
<td>&#8216;%m/%d/%Y&#8217;</td>
<td>04/25/2009</td>
</tr>
<tr>
<td>&#8216;%a %D %b %Y&#8217;</td>
<td>Fri 25th Apr 2009</td>
</tr>
</table>
<p>A more complete list of specifiers is available <a href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://boolean.co.nz/blog/mysql-date_format/118/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

