<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>Lynch Consulting Blog - mysql</title>
			<link>http://www.lynchconsulting.com.au/blog/index.cfm</link>
			<description>A blog about ColdFusion, PHP, Flash, Flex, Web Standards and a mish mash of other technologies</description>
			<language>en-us</language>
			<pubDate>Tue, 07 Sep 2010 12:51:18 --1000</pubDate>
			<lastBuildDate>Fri, 29 Jan 2010 08:15:00 --1000</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>mark@lynchconsulting.com.au</managingEditor>
			<webMaster>mark@lynchconsulting.com.au</webMaster>
			
			
			
			
			
			<item>
				<title>MySQL 5.1 logging changes - Log to DB and runtime config</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2010/1/29/MySQL-51-logging-changes</link>
				<description>
				
				While browsing around the MySQL site last night I discovered a number of nice new features of mysql 5.1 that relate to logging.

These are:

&lt;ul&gt;
&lt;li&gt;Logging to DB instead of log files&lt;/li&gt;
&lt;li&gt;Runtime configuration of logging.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Logging to DB instead of log files&lt;/h3&gt;

Coming from a web development background rather than a sysadmin background I&apos;m far more comfortable manipulating and analysing data using SQL.  So to be able to log all the queries or just the slow queries for an application to the db during application development or load testing is a huge benefit.

To enable logging to DB you can add the following to your my.cnf
&lt;code&gt;
log_output = TABLE
&lt;/code&gt; 

The logs will be written to the &apos;slow_log&apos; and &apos;general_log&apos; tables in the mysql database.

Note - logging to tables has more overhead than logging to file, so would suggest using it primarily for development purposes.

Full details of the options are on the &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.1/en/log-tables.html&quot;&gt;mysql manual on log tables&lt;/a&gt;


&lt;h3&gt;Runtime configuration of logging.&lt;/h3&gt;

This allows you to turn on and off logging without restarting MySQL - which just saves a little bit of time and makes it much nicer for debugging problems.

To turn on the logging of all queries run:
&lt;code&gt;
SET GLOBAL general_log = &apos;ON&apos;;
&lt;/code&gt;
And for just the slow query log:
&lt;code&gt;
SET GLOBAL slow_query_log = &apos;ON&apos;;
&lt;/code&gt;

And to turn them both off use:
&lt;code&gt;
SET GLOBAL general_log = &apos;OFF&apos;;
SET GLOBAL slow_query_log = &apos;OFF&apos;;
&lt;/code&gt;

If you also want to see queries not using indexes in the slow query log you can set the following variable:

&lt;code&gt;
SET GLOBAL log_queries_not_using_indexes = &apos;ON&apos;;
&lt;/code&gt;


Hope it helps,
Mark
				
				</description>
				
				<category>Ubuntu</category>
				
				<category>Systems admin</category>
				
				<category>Open Source</category>
				
				<category>mysql</category>
				
				<category>Linux</category>
				
				<category>Database</category>
				
				<pubDate>Fri, 29 Jan 2010 08:15:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2010/1/29/MySQL-51-logging-changes</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>CFMX Query Timeout Gotcha</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2009/5/19/CF-Timeout</link>
				<description>
				
				NOTE: I found this blog post in my to be posted ones from 2008.

While doing some load testing a while back we came across a strange error while simulating the load that we were expecting.  The simulated load had a large first peak, followed by a quieter period, followed by some more peaks.

During the load test we noticed a few query errors that we had never seen before, they related to the query connection timing out.

It turns out that the way CF times out datasource connections is slightly quirky as described below: 

&lt;blockquote&gt;
The other timeout setting in the CF Admin datasource detail page is just labeled as Timeout, with a paired setting for Interval. This timeout value is how long a connection should be idle before it is removed. So if a connection goes unused for this period of time, then the next time ColdFusion checks that connection it will be removed from the pool. The frequency that ColdFusion checks the connection idle time is set by the Interval setting. The default for the Timeout setting is 20 minutes and the Interval is 7 minutes, so every 7 minutes ColdFusion will check connections for that datasource and remove connections that have been idle for 20 minutes or more. The number of connections idle connections removed from the pool at each interval is &lt;strong&gt;hardcoded in ColdFusion to just five.&lt;/strong&gt; Say you have 20 idle connections hanging around in a pool, this would require at least 28 minutes to be cleaned up.

&lt;dl&gt;
&lt;dt&gt;Timeout (min)&lt;/dt&gt;
&lt;dd&gt; The number of minutes that ColdFusion MX maintains an unused connection before destroying it.&lt;/dd&gt;
&lt;dt&gt;Interval (min)&lt;/dt&gt;
&lt;dd&gt;The time (in minutes) that the server waits between cycles to check for expired data source connections to close.
&lt;/dd&gt;
&lt;/dl&gt;

&lt;/blockquote&gt;

Cheers,
Mark
				
				</description>
				
				<category>mysql</category>
				
				<category>ColdFusion</category>
				
				<pubDate>Tue, 19 May 2009 14:04:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2009/5/19/CF-Timeout</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Loading MySQL timezone info on Linux and Macs</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2008/9/8/Loading-MySQL-timezone-info-on-Linux-and-Macs</link>
				<description>
				
				MySQL has some really useful functions that make timezone support a bit easier &lt;a href=&quot;http://www.lynchconsulting.com.au/blog/index.cfm/2007/4/29/CFMX-applications-on-servers-with-different-time-zones&quot;&gt;as described in a previous blog post.&lt;/a&gt;.

However, you need to do a tiny bit of setup work before you can use the functions.  You need to load the timezone info from your system into the mysql db.

Thankfully, the MySQL Developers have included a very handy script that will do just that from a zoneinfo files which are used on Linux and on Mac&apos;s.

&lt;code&gt;
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
&lt;/code&gt;

Obviously change the mysql params or add a -p if you have a password or are connecting to a remote server.

Check out the MySQL developer site for &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.0/en/time-zone-support.html&quot;&gt;full details on MySQL timezone support&lt;/a&gt;

Cheers,
Mark
				
				</description>
				
				<category>mysql</category>
				
				<category>Mac OSX</category>
				
				<category>Linux</category>
				
				<category>Database</category>
				
				<category>Open Source</category>
				
				<pubDate>Mon, 08 Sep 2008 13:30:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2008/9/8/Loading-MySQL-timezone-info-on-Linux-and-Macs</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>MySQL and Temporary tables and CASE syntax</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2008/8/31/MySQL-and-Temporary-tables-and-CASE-syntax</link>
				<description>
				
				For some reason I&apos;ve always avoided the use of temporary tables in SQL (MySQL or otherwise) but today I came across a difficult problem that temporary tables made very simple.  

I needed to use a case function on a subquery value to return a tri-state value.  I.e. yes, no or partial.

The cut down query below demonstrates how it works.

&lt;ul&gt;
&lt;li&gt;First we drop the temporary table in case one has been left lying around.&lt;/li&gt;
&lt;li&gt;Then we select a query into the temporary table which include some complex subqueries.&lt;/li&gt;
&lt;li&gt;We can then query the temporary table to do further processing on the result, which in this case depending on the values of the class_count and class_count_assigned allows us to set a field in three states.
&lt;ul&gt;
&lt;li&gt;&apos;yes&apos; if all users for a class are selected&lt;/li&gt;
&lt;li&gt;&apos;partial&apos; if some users are selected&lt;/li&gt;
&lt;li&gt;&apos;no&apos; if none are selected.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;code&gt;
&lt;cfquery name=&quot;q&quot; datasource=&quot;#variables.myDSN#&quot;&gt;
	DROP TEMPORARY TABLE  IF EXISTS tmp_exams;
	/* Create temporary table query which includes student counts */
	CREATE TEMPORARY TABLE tmp_exams
	SELECT	e.id
			, e.name
			, (SELECT count(1) FROM tbl_user_classes uXc
                WHERE uXc.school_class_id = &lt;cfqueryparam value=&quot;#arguments.school_class_id#&quot; cfsqltype=&quot;cf_sql_integer&quot;&gt;) AS class_count
            , (SELECT count(1) FROM tbl_user_classes uXc
                INNER JOIN  tbl_users_exams uXe ON uXe.user_id = uXc.user_id
                WHERE uXc.school_class_id = &lt;cfqueryparam value=&quot;#arguments.school_class_id#&quot; cfsqltype=&quot;cf_sql_integer&quot;&gt;
                AND exam_id = e.id) AS class_count_assigned
	FROM	tbl_exams e;
	/* Select out the relevant info */
	SELECT e.id
			, e.name
			, e.class_count
			, e.class_count_assigned
		    ,(CASE WHEN class_count_assigned = 0 THEN &apos;no&apos;
		    	WHEN class_count = class_count_assigned THEN &apos;yes&apos;
		    	ELSE &apos;partial&apos; END) AS active
	FROM tmp_exams e
	WHERE	1=1
	ORDER BY e.name
&lt;/cfquery&gt;
&lt;/code&gt;

Mostly posted for my future reference but hope it helps out.

Cheers,
Mark
				
				</description>
				
				<category>Database</category>
				
				<category>ColdFusion</category>
				
				<category>mysql</category>
				
				<pubDate>Sun, 31 Aug 2008 20:47:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2008/8/31/MySQL-and-Temporary-tables-and-CASE-syntax</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>PHP and MySQL 5 bit fields</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2008/8/25/PHP-and-MySQL-5-bit-fields</link>
				<description>
				
				While debugging some PHP code the other night I came across a particularly strange problem with MySQL Bit fields.

I was returning a query with some bit fields into my class but the it was not returning true or false when I switched the data.

A bit of hunting and it turned out the that it was being returned as a binary type and after a few failed attempts to convert it to an integer or boolean on the PHP side I found &lt;a href=&quot;http://pear.php.net/bugs/bug.php?id=10211&quot;&gt;this bug report on it&lt;/a&gt;.

So the moral of the story is if you are selecting BIT types from a mysql DB in PHP don&apos;t do this:

&lt;code&gt;
 SELECT myBit
 FROM tbl_example
 WHERE id = 1
&lt;/code&gt;

Instead cast the bit to an integer in MySQL like so:
&lt;code&gt;
 SELECT CAST(myBit AS unsigned integer) AS myBit, 
 FROM tbl_example
 WHERE id = 1
&lt;/code&gt;

Voila, it works like expected.

Cheers,
Mark Lynch
				
				</description>
				
				<category>Open Source</category>
				
				<category>mysql</category>
				
				<category>Database</category>
				
				<category>PHP</category>
				
				<pubDate>Mon, 25 Aug 2008 12:21:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2008/8/25/PHP-and-MySQL-5-bit-fields</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>CF Sandbox Security Tricks and Tips</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2008/8/13/CF-Sandbox-Security-Tricks-and-Tips</link>
				<description>
				
				I&apos;ve been working on getting CF Sandbox security working.  It&apos;s trickier than I first thought so here&apos;s how to do it for future reference:

&lt;h3&gt;Enable security Manager&lt;/h3&gt;
Instructions from &lt;a href=&quot;http://www.talkingtree.com/blog/index.cfm/2006/7/11/SBS-Known-Issues&quot;&gt;Steven Erat&apos;s blog&lt;/a&gt;:
&lt;code&gt;
Stop ColdFusion.
Locate the jvm.config file in jrun_root/bin.
Back up the file.
Open the file in a text editor.
Add the following lines to the java.args section:
-Djava.security.manager
&quot;-Djava.security.policy=[cf_webapp_root]/WEB-INF/cfusion/lib/coldfusion.policy&quot;
&quot;-Djava.security.auth.policy=[cf_webapp_root]/WEB-INF/cfusion/lib/neo_jaas.policy&quot;
&lt;/code&gt;

NOTE the example from the adobe site has the quotes in the wrong place. 
Note you also need to change [cf_webapp_root] to match the location on your machine.


&lt;h3&gt;Datasources&lt;/h3&gt;

After I enabled Datasource security I began to receive the following error, a bit of digging reminded me that the MySQL connector tries to do some autoconfiguration for coldfusion to optimise it.

&lt;code&gt;
Message: Can&apos;t find configuration template named &apos;coldFusion&apos; 
Type: java.sql.SQLException 
&lt;/code&gt;

It was failing to load the configuration file which is inside the mysql connector jar file  /com/mysql/jdbc/configs/coldFusion.properties

I haven&apos;t gotten to the bottom of why it couldn&apos;t be loaded but adding the following to the datasource query string fixed it up: &lt;code&gt;
autoConfigureForColdFusion=false
&lt;/code&gt;

I would suggest adding some of the settings from this file as paramaters in your &lt;a href=&quot;http://www.lynchconsulting.com.au/blog/index.cfm/2008/6/1/Show-Full-Columns-problem-with-CFMX-and-MySQL-solved&quot;&gt;datasource settings as per previous post&lt;/a&gt;


Note: This was using the following:
&lt;ul&gt;
&lt;li&gt;ColdFusion 7.0.2 Cumulative Hotfix 1 Multiserver install&lt;/li&gt;
&lt;li&gt;MySQL connector/J 5.0.8&lt;/li&gt;
&lt;/ul&gt;

Hope it helps.
Cheers,
Mark
				
				</description>
				
				<category>Open Source</category>
				
				<category>mysql</category>
				
				<category>Linux</category>
				
				<category>ColdFusion</category>
				
				<pubDate>Wed, 13 Aug 2008 11:07:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2008/8/13/CF-Sandbox-Security-Tricks-and-Tips</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>&quot;Show Full Columns&quot; problem with CFMX and MySQL solved</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2008/6/1/Show-Full-Columns-problem-with-CFMX-and-MySQL-solved</link>
				<description>
				
				We&apos;ve been performing some load testing on a new website we&apos;ve developed and our helpful sysadmin noticed lots of queries happening on the DB that looked like this:

&lt;code&gt;
SHOW FULL COLUMNS FROM `dbname`.`tablename`
&lt;/code&gt;

We weren&apos;t intentionally doing these queries but they were coming from somewhere.  A bit of detective work via google found &lt;a href=&quot;http://whirlpool.net.au/blog/5 &quot;&gt; a very enlightening article about this problem&lt;/a&gt;.

A quick read of this explained: 
&lt;blockquote&gt;
It turns out ColdFusion was asking Connector/J for the metadata on every field, which in turn triggered a SHOW FULL COLUMNS query for every varchar and text column returned.
&lt;/blockquote&gt;

It also went on to say that is had been &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.0/en/cj-news-5-0-7.html&quot;&gt;fixed as of Connector/J 5.07&lt;/a&gt;.

On reading the release notes it mentions that the
&lt;blockquote&gt;
Driver detects when it is running in a ColdFusion MX server (tested with version 7), and uses the configuration bundle coldFusion, which sets useDynamicCharsetInfo to false (see previous entry), and sets useLocalSessionState and autoReconnect to true. 
&lt;/blockquote&gt;

However, from my testing it wasn&apos;t doing it as we were still seeing the problem.  However, we are running the MultiServer version of ColdFusion which sits atop Jrun4.

So I added the parameter directly to the querystring:
&lt;code&gt;
&amp;useDynamicCharsetInfo=false
&lt;/code&gt;
So it now looks like:
&lt;code&gt;
jdbc:mysql://127.0.0.1:3306/mydbname?allowMultiQueries=true&amp;useDynamicCharsetInfo=false
&lt;/code&gt;

This has stopped the problem, and given a significant performance gain.  On one of the sites I was load testing it gave a 12% throughput increase and on another one which had less queries it gave a 4% increase.

Hope it helps.

Cheers,
Mark
				
				</description>
				
				<category>Open Source</category>
				
				<category>mysql</category>
				
				<category>Java</category>
				
				<category>Database</category>
				
				<category>ColdFusion</category>
				
				<category>Systems admin</category>
				
				<pubDate>Sun, 01 Jun 2008 21:01:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2008/6/1/Show-Full-Columns-problem-with-CFMX-and-MySQL-solved</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>CF 7.0.2 Cumulative Hotfix 2 breaks MySQL Multiple Queries</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2008/4/23/CF-702-Cumulative-Hotfix-2-breaks-MySQL-Multiple-Queries</link>
				<description>
				
				I&apos;ve just spent a while figuring out a painful bug in CF and am posting here so that I can reference it from the Adobe bug tracker as I can&apos;t explain the problem in 2000 characters.

&lt;h2&gt;Summary of Problem&lt;/h2&gt;

CF 7.0.2 Cumulative Hotfix 2 and 3 breaks the use of Multiple SQL statements with MySQL connectorJ connector.

This is a regression as it works perfectly in CF 7.0.2 and CF 7.0.2 with Cumulative hotfix 1.

I have tested the following configurations:
&lt;ul&gt;
&lt;li&gt;CF7.0.2 MySQL connectorJ 5.0.8  - works&lt;/li&gt;
&lt;li&gt;CF7.0.2 hotfix 1 MySQL connectorJ 5.0.8  - works&lt;/li&gt;
&lt;li&gt;CF7.0.2 hotfix 2 MySQL connectorJ 5.0.8  - broken&lt;/li&gt;
&lt;li&gt;CF7.0.2 hotfix 3 MySQL connectorJ 5.0.8  - broken&lt;/li&gt;
&lt;li&gt;CF7.0.2 MySQL connectorJ 3.1.10  - works&lt;/li&gt;
&lt;li&gt;CF7.0.2 hotfix 1 MySQL connectorJ 3.1.10  - works&lt;/li&gt;
&lt;li&gt;CF7.0.2 hotfix 2 MySQL connectorJ 3.1.10  - broken&lt;/li&gt;
&lt;li&gt;CF7.0.2 hotfix 3 MySQL connectorJ 3.1.10  - broken&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Steps to reproduce bug:&lt;/h2&gt;


1. Set up a CF 7.0.2 Multiserver install with built in webserver

2. Download and install ConnectorJ JDBC driver for MySQL and install as per Adobe Technote &lt;a href=&quot;http://www.adobe.com/go/6ef0253&quot;&gt;http://www.adobe.com/go/6ef0253&lt;/a&gt;

3. Create a mysql database named &quot;test&quot; the and create a table with the following script:

&lt;code&gt;
CREATE TABLE `tbl_test` ( 
	`id`  	int(11) AUTO_INCREMENT NOT NULL,
	`data`	varchar(50) NULL,
	PRIMARY KEY(`id`)
)
&lt;/code&gt;

4. In CF Admin create a DSN named dsn_test with following settings
&lt;ul&gt;
&lt;li&gt;JDBC Url: jdbc:mysql://127.0.0.1:3306/test?allowMultiQueries=true&lt;/li&gt;
&lt;li&gt;Driver Class: com.mysql.jdbc.Driver&lt;/li&gt;
&lt;li&gt;Driver name: (leave blank)&lt;/li&gt;
&lt;li&gt;username: (valid user for your db - default: root)&lt;/li&gt;
&lt;li&gt;password: (valid password for your db - default: &apos;blank&apos;)&lt;/li&gt;
&lt;li&gt;Place the following file in the /opt/jrun4/servers/cfusion/cfusion-ear/cfusion-war directory&lt;/li&gt;
&lt;/ul&gt;
 

&lt;code&gt;
MySQL driver version:
&lt;cftry&gt;
&lt;cfset oDriver = createObject(&quot;java&quot;,&quot;com.mysql.jdbc.Driver&quot;)&gt;
&lt;cfoutput&gt; #oDriver.getMajorVersion()#.#oDriver.getMinorVersion()#&lt;/cfoutput&gt;
&lt;cfcatch type=&quot;any&quot;&gt;
	Unknown
&lt;/cfcatch&gt;
&lt;/cftry&gt;

&lt;cfquery name=&quot;qTest&quot; datasource=&quot;dsn_test&quot;&gt;
	INSERT INTO tbl_test (data)
	VALUES (&apos;Test String&apos;);
	SELECT LAST_INSERT_ID() as lastInsertID;
&lt;/cfquery&gt;
&lt;cftry&gt;
&lt;cfdump var=&apos;#qTest#&apos;&gt;
&lt;cfcatch type=&quot;any&quot;&gt;
	No Query set returned from query.
&lt;/cfcatch&gt;
&lt;/cftry&gt;
&lt;/code&gt;

This code should function correctly and return a cfdump of the auto generated primary key as per &lt;a href=&quot;http://www.lynchconsulting.com.au/blog/enclosures/expected.png&quot;&gt;expected screenshot&lt;/a&gt;. 


Next apply Coldfusion Cumulative hotfix 2 and restart coldfusion as per Adobe Technote  http://www.adobe.com/go/kb400996


Re run the test and no query set will be returned from the driver.  The qTest variable does not get set as per the  &lt;a href=&quot;http://www.lynchconsulting.com.au/blog/enclosures/broken.png&quot;&gt;broken screenshot&lt;/a&gt;. 


&lt;h2&gt;Related Resources&lt;/h2&gt;
Technote re upgrading MySQL JDBC Drivers &lt;a href=&quot;http://www.adobe.com/go/6ef0253&quot;&gt;http://www.adobe.com/go/6ef0253&lt;/a&gt;


CF Updates page &lt;a href=&quot;http://www.adobe.com/support/coldfusion/downloads_updates.html#mx7&quot;&gt;http://www.adobe.com/support/coldfusion/downloads_updates.html#mx7&lt;/a&gt;


CF 7.0.2 Cumulative hot 3 &lt;a href=&quot;http://www.adobe.com/go/kb402465&quot;&gt;http://www.adobe.com/go/kb402465&lt;/a&gt;


CF 7.0.2 Cumulative hot 2 &lt;a href=&quot;http://www.adobe.com/go/kb400996&quot;&gt;http://www.adobe.com/go/kb400996&lt;/a&gt;


CF 7.0.2 Cumulative hot 1 &lt;a href=&quot;http://www.adobe.com/go/kb400074&quot;&gt;http://www.adobe.com/go/kb400074&lt;/a&gt;


MySQL ConnectorJ &lt;a href=&quot;http://www.mysql.com/products/connector/j/&quot;&gt;http://www.mysql.com/products/connector/j/&lt;/a&gt;


MySQL ConnectorJ 3.1.10 Download: &lt;a href=&quot;http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.10.tar.gz/from/pick#mirrors&quot;&gt;http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.10.tar.gz/from/pick#mirrors&lt;/a&gt;
				
				</description>
				
				<category>Database</category>
				
				<category>ColdFusion</category>
				
				<category>mysql</category>
				
				<pubDate>Wed, 23 Apr 2008 13:40:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2008/4/23/CF-702-Cumulative-Hotfix-2-breaks-MySQL-Multiple-Queries</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>Multiple queries with CFMX-MySQL JDBC connector</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2008/2/10/Multiple-queries-with-CFMXMySQL-JDBC-connector</link>
				<description>
				
				I found a little snippet the other day and included it in the tail end of a previous post - however, on reflection I thought it deserved a post of it&apos;s own.

If you want to utilise multiple queries per sql statement and you are using the MYSQL JDBC connector you need to add the following to your jdbc connector querystring.
&lt;code&gt;
allowMultiQueries=true
&lt;/code&gt;
So you querystring would look like:
&lt;code&gt;
jdbc:mysql://127.0.0.1:3306/mydbname?allowMultiQueries=true
&lt;/code&gt;

This will allow you to do queries like the following to return autoincrement values:
&lt;code&gt;

&lt;cfquery name=&quot;qInsert&quot; datasource=&quot;mydsn&quot;&gt;
 INSERT INTO tbl_demo (name)
 VALUES ( &lt;cfqueryparam value=&quot;#myName#&quot;&gt;);
 SELECT last_insert_id() as newID
&lt;/cfquery&gt;
&lt;cfoutput&gt;ID of value is: #qInsert.newID#&lt;/cfoutput&gt;

&lt;/code&gt;

Please note however that this functionality is disabled as it can leave the door open for SQL Injection attacks.  However, as long as you always use cfqueryparam for all the dynamic parts of your query you will be fine.
				
				</description>
				
				<category>Database</category>
				
				<category>ColdFusion</category>
				
				<category>mysql</category>
				
				<pubDate>Sun, 10 Feb 2008 21:32:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2008/2/10/Multiple-queries-with-CFMXMySQL-JDBC-connector</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>CFMX Mysql Query String for UTF8 and Multiple Queries</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2008/2/7/CFMX-Mysql-Query-String-for-UTF8-and-Multiple-Queries</link>
				<description>
				
				While testing some of the code we&apos;ve written for UTF8 support for double byte characters (Chinese, Japanese, Malaysian) I discovered that there are some voodoo JDBC connection string parameters that have to be set to make it work.

Firstly, CFMX used UTF8 by default so it&apos;s already configured. You need to make sure that your MySQL DB table has a Charset of utf8 as per example below:

&lt;code&gt;
CREATE TABLE `utf8test` ( 
	`id`     	int(11) NOT NULL,
	`data`    	varchar(25) NULL,
	PRIMARY KEY(`id`)
)CHARACTER SET utf8 COLLATE utf8_general_ci;
&lt;/code&gt;

Then you need to add the following params to the connection string:
&lt;ul&gt;
&lt;li&gt;characterEncoding=UTF8&lt;/li&gt;
&lt;li&gt;characterSetResults=UTF8&lt;/li&gt;
&lt;/ul&gt;

I also add the &quot;allowMultiQueries=true&quot; string which allows you to execute multiple queries in the one statement.  It is disabled by default as it can open up a window for SQL Injection attacks, but this can be mitigated by always using CFQUERYPARAM&apos;s.

So the final connection string looks like this:
&lt;code&gt;
jdbc:mysql://127.0.0.1:3306/utf8demo?allowMultiQueries=true&amp;characterEncoding=UTF8&amp;characterSetResults=UTF8
&lt;/code&gt;

Hope it helps,
Cheers,
Mark
				
				</description>
				
				<category>mysql</category>
				
				<category>Database</category>
				
				<category>ColdFusion</category>
				
				<category>Open Source</category>
				
				<pubDate>Thu, 07 Feb 2008 12:56:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2008/2/7/CFMX-Mysql-Query-String-for-UTF8-and-Multiple-Queries</guid>
				
			</item>
			
		 	
			
			
			<item>
				<title>HOWTO Backup and restore MySQL db&apos;s</title>
				<link>http://www.lynchconsulting.com.au/blog/index.cfm/2007/11/22/HOWTO-Backup-and-restore-MySQL-dbs</link>
				<description>
				
				Handy reference for backing up and restoring db&apos;s via the mysql command line tools as it is by far the quickest way to do it.

We do this regularly as we take copies of our staging db&apos;s from a central DB server and put them on our local machines for development work.

&lt;h3&gt;Backup a database &amp; zip it up&lt;/h3&gt;
&lt;code&gt;
mysqldump -h db.example.com -p mydbname | gzip &gt; mydbname.sql.gz
&lt;/code&gt;

This will back the mydbname database from the server db.example.com and will prompt for a password (much better than writing it in the command line) and will then gzip it into the file mydbname.sql.gz

&lt;h3&gt;Create a database (if it doesn&apos;t exist)&lt;/h3&gt;
&lt;code&gt;
mysqladmin -h 127.0.0.1 -u root create mydbname
&lt;/code&gt;
This is only necessary the first you are creating a copy of the db on your machine.


&lt;h3&gt;Restore DB backup&lt;/h3&gt;
&lt;p&gt;Note: this will overwrite all local changes to the DB&lt;/p&gt;

&lt;code&gt;
zcat mydbname.sql.gz | mysql -h 127.0.0.1 -u root mydbname 
&lt;/code&gt;
This will take your previously gzipped backup copy and restore it into the local mysql instance to the db called mydbname

Hope it helps.
Cheers,
Mark
				
				</description>
				
				<category>Open Source</category>
				
				<category>mysql</category>
				
				<category>HOWTO</category>
				
				<category>General</category>
				
				<category>ColdFusion</category>
				
				<category>Systems admin</category>
				
				<pubDate>Thu, 22 Nov 2007 20:08:00 --1000</pubDate>
				<guid>http://www.lynchconsulting.com.au/blog/index.cfm/2007/11/22/HOWTO-Backup-and-restore-MySQL-dbs</guid>
				
			</item>
			
		 	
			</channel></rss>