Steven Erat's Blog Steven Erat Photography
 
 
Viewing By Entry
 
 

TalkingTree  How to connect ColdFusion MX to MySQL 4.1 database

 

UPDATE: This article has been published as a technote, and later updated for MySQL 4 and 5.

Having not gone to Macromedia MAX this year, I'm glued to the tube this evening watching the 2004 presidential election results. Dan Rather's pontifications, prognostications, and random musings are starting my make my eyes glaze over, so to remedy that, I'll take a quick break here to share some information about how to connect to MySQL 4.1 from ColdFusion MX server.
First, does ColdFusion MX 6.1 server officially support MySQL 4.1? Good question! The System Requirements state support for MySQL without reference to a specific version, whereas the other database vendors are listed with supported versions. Second, ColdFusion MX 6.1 has not yet been tested for MySQL 4.1 given that just last week MySQL 4.1 was officially certified as production ready. Third, the MySQL driver option listed in the ColdFusion Administrator is hard-coded in neo-query.xml to use the MySQL 3.2 JDBC driver, org.gjt.mm.mysql.Driver.


There are two significant steps to configure ColdFusion MX to use MySQL 4.1: Including the MySQL Connector J in the ColdFusion server classpath, and using the Other driver type from the drop down list to specify the driver class com.mysql.jdbc.Driver.

Here's the detailed list:
Steps to Configure ColdFusion MX for MySQL 4.1

  • Download the MySQL Connector J JDBC driver
  • Make the JDBC driver available to CFMX through the classpath by saving mysql-connector-java-3.0-bin.jar in either $CFMX_HOME/runtime/servers/lib/ for CFMX Server Configuration or $JRUN_HOME/servers/lib/ for CFMX on JRun Configuration. This makes the driver available to all JRun server instances.
  • Restart CFMX server.
  • Add new datasource using the driver option Other
  • Add the JDBC URL jdbc:mysql://[host]:[port]/[database]
  • Add the Driver Class com.mysql.jdbc.Driver
  • Complete username/password, and adjust other dsn settings if needed.
  • Submit datasource for verification

If you select the existing MySQL driver option in CFMX to connect to a MySQL 4.1 database, then it will fail with the error message below since neo-query.xml is configured to use the "old" JDBC driver class.

The error is:

Connection verification failed for data source: mysql_bad java.sql.SQLException: Communication failure during handshake.Is there a server running on localhost:3306?
The root cause was that: java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?

You'll probably want to set up a MySQL user account for use with your application, so check out the MySQL documentation for adding new user accounts, section 5.6.2 Adding New User Accounts to MySQL. Be sure to set the GRANT statements properly to permit the user to connect to the desired databases from the host that CFMX resides on.


To administer your MySQL database, I highly recommend the free application from Digital Crew called CFMyAdmin, comparable to PhpMyAdmin. Out of the box, CFMyAdmin 1.0 (Beta 3) will not work with MySQL 4.1. To correct this, just find the wddx config file CFMyAdmin/modules/MySQLDSWDDX.z, then change the driver CLASS from org.gjt.mm.mysql.Driver to com.mysql.jdbc.Driver. Once that's done, just launch the CFMyAdmin application in a browser and create a new connection using the new mysql user account that you've just set up.


I'll post back when I get better information on the official ColdFusion MX support for MySQL 4.1 database. Incidentally, I successfully tested with Blackstone Beta 2 as well.

 


Comments

I've found you don't need to use the updated connector: the handshake error simply results from a change in the authentication in 4.1, which you can get round by setting a pre 4.1 style password for the account you set up for CF:

mysql> SET PASSWORD FOR
-> 'coldfusion'@'localhost' = OLD_PASSWORD('newpwd');

See http://www.devshed.com/c/a/MySQL/Troubleshooting-Problems-with-MySQL-Programs/2 for more detail.


True, but I would imagine that its best to use a current driver version with a current database version.


steven are you recommending that drivers, etc. be placed in CFMX_HOME/runtime/servers/lib/ rather than wwwroot/web-inf/lib ?


Hi Paul, no, I'm not recommending servers/lib necessarily. That's up to you. servers/lib will make a class available across all JRun server instances if you're running CFMX on JRun4. If you're using the server configuration, then WEB-INF/lib would be fine. As I'm sure you know, WEB-INF/lib is application specific, not server-wide nor servers-wide.


This post helped me a lot. Thanks!


Is there any problem with putting the new driver in $CF_HOME/lib (i.e., /opt/coldfusionmx/lib). It seems to work for me.


As long as the driver is somehow in the classpath, then it will work.

By convention:
   - jar's specific to a J2EE web application go into the web's servers/{server}/{ear}/{war}/WEB-INF/lib   
   - jar's to be available to all web application J2EE server instance go in servers/lib

ColdFusion server configuration also happens to load from {cfhome}/lib, and ColdFusion J2EE configuration also loads from servers/{server}/{ear}/{war}/WEB-INF/cfusion/lib.

If there are others that manage the ColdFusion or J2EE server, then it might be best to put new jars in the conventional location.


Thanks so much, Steven! I ran into this problem today and this helped a lot!


Cool. Glad I could help :)


I've confirmed that Macromedia does support the use of MySQL 4.1 with ColdFusion MX, with the use of the appropriate MySQL Connector J JDBC driver.

Problems that can be isolated to the driver or database are of course unsupported, but everything else is fair game.

Another thread like this is going on at Matt Woodward's blog:
http://www.mattwoodward.com/blog/index.cfm?mode=en...


Christian Cantrell has posted a blog entry about how to configure MySQL 4.1 tables and ColdFusion datasources for them to use Unicode character sets:
http://www.markme.com/cantrell/archives/007078.cfm...


I keep getting this:

Connection verification failed for data source: test
java.sql.SQLException: Timed out trying to establish connection
The root cause was that: java.sql.SQLException: Timed out trying to establish connection

Using CFMX7 on WinXP. Have been running both 4.1 and 5.0beta MySQL. Have tried both alpha and production the MySQL J connectors. Nothing seems to work, yet I can connect without problem to both MySQL instances through php and via the console.

Have you come across this?--very frustrating.


Got it to work.

Turns out I had placed multiple versions of the MySQL/J Connector jar file in the CF directories, in some desparate attempt to get things to work. I believe CF was finding an old (or possibly corrupted) connector first, in its search through the class path. I ditched all of the redundant connector jar files, downloaded the stable one (3.1.8a), and was able to connect to both of my MySQL instances (versions 4.1 and 5.0beta), after restarting the CF service.

Sorry for taking up the blog space, above. Hope this might help someone. At least I can confirm this works.


Thanks for taking the time to post your solution!


We have run into trouble using MySQL with CFMX 6.1. We have set everything up as recommended here, but on our production server CF hangs. In the browser all you see is something like ">." on the page.

We've tried placing MySQL locally on the machine and on another server. This error doesn't always occur immediately but consistently happens after a short period of time. It isn't a load issue as we had only put it into place for a test app.

This does not happen on our development box which is set up the same.

Any input would be appreciated.


Luis, the problem you report was bug 59740 and has nothing to do with the MySQL JDBC driver. The bug was introduced in Updater 1 for CFMX 6.1, and this article includes a hotfix for it:

http://www.macromedia.com/go/238944b1

In short, the .< text is supposed to be an error message reported by the web server connector. The actual error message should be "Server Error", and that could in turn be caused by a variety of server problems.


I keep getting Invalid list index 243 when I connect to my database with CFMyAdmin, any ideas?


Just upgraded MySQL on my server from 4.0.25 to 4.1.13 which went fine. Now, I hadn't updated my DSN's, although had put the J connector driver in servers/lib and all of them work fine using the built in MySQL driver??

Is this an update I've applied that makes it work or will some feature of 4.1 not be available until I upgrade the driver?


Another option is to load the connection class remotely.

Code:
http://www.geocities.com/empiricallyspeaking//Remo...

view of the error message:
http://www.geocities.com/empiricallyspeaking//mysq...


Hi,
I am wondering if you could point me to the MySQL 3.2 JDBC driver?
I looked all over the MySQL site, but can't find any links to this file. Is the 3.1 the latest currently in use? I also see on thier site that there is connector 5(in alpha). The site that keeps comming up is:
http://dev.mysql.com/downloads/connector/j/3.1.htm...

I can't fins the 3.2 version that you talk about here. The link you provide is broke.

I am using MySQL 5.0, and using the connector 3.1.1. However, I hear that updating the connector may solve a problem that I am trying to find a solution for.

Thanks for any help that you may be able to provide,
Thanks in advance John


John, I also noticed that the MySQL website is lacking a download for the 3.2 driver version, maybe it was not a stable release.

I found another site that provides a link for the 3.2 Connector/J JDBC Driver for MySQL:
http://www.my-sql.org/index.php/downloads/connecto...


Hi Steven,
Thanks for the link.
John


I am trying to connect to a MySQL database located in the godaddy.com shared host program. Can anyone help me please I tried everything but the right thing. :( I just did the suggested by this page..
by the way godaddy.com runs MySQL 4.0.12 and they support CF MX 7. I have CF MX 7 and there is just no way to connect to their database. This is the rror I get

Connection verification failed for data source: MySQL_quotes
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect
The root cause was that: java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused: connect

Please help anyone..


Steven, would there be any logic in the fact that the jdbc driver appears to be much slower than using the mysql 3.x driver already included in coldfusion (using the method that Julian describes in the first comment)? On running the same queries side by side on the same page each with a different driver, off a mysql 5 database (have to use the old_password setting to make the 3.x one work), the mysql one appears to be 10x faster. It's hard to believe this is true, especially as I can't find any mention of it elsewhere, but it made a huge difference on a site I just launched and on local testing it is holding true! Note that this is a 3.1.13 connector, so perhaps it is just that version, but even then it's strange that no one else has mentioned this? I'd be really interested to hear from others if they can recreate this.


ye its working. thanks


 

 

Calendar

 
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Search This Site

 
This is an exact search only

About This Site

 
I live west of Boston and work as a Software Engineer with ColdFusion and Flex, specializing in Linux. Recently I graduated in Professional Digital Photography from CDIA.
More about me

Recent Entries

 
A ColdFusion Trick for Lost D..
Starting ColdFusion9 Solr: Us..
Adobe LiveCycle DataServices ..

Recent Comments

 
Posted By Aaron Longnion:
Thanks Steven, I just ran into this problem, remembered your tweet about it, and found your blog on it. :)

Posted By srinyvas:
Hai, This information is very useful and i like your excellent writing skill. Can i copy this Content to my website top management colleges ...

Posted By Steven Erat:
@Wade - Glad I could help! Thanks for letting me know it worked for you too.

recently played

 
The Candid Frame #70 - Greg Gorman
by Ibarionex R. Perello
on The Candid Frame: A Photography Podcast

now playing, a plug-in for itunes

Categories

 
RSS Adobe (34)
RSS Bicycling (9)
RSS Blogging (39)
RSS Books (13)
RSS Breeze (13)
RSS CFMX Podcasts (10)
RSS ColdFusion (427)
RSS Computer Technology (51)
RSS Events (26)
RSS Flex (20)
RSS Gadgets (10)
RSS HiTech Industry (16)
RSS Java (25)
RSS Learning (57)
RSS Linux (70)
RSS Mac OS X (22)
RSS Macromedia (27)
RSS Meetup (35)
RSS New England (62)
RSS Odds & Ends (25)
RSS Outdoors (32)
RSS Personal (29)
RSS Photography (111)
RSS Photoshop (29)
RSS Podcasts (18)
RSS Rants (19)
RSS Restaurants (8)
RSS Science (34)
RSS Spain (16)
RSS Travel (42)
RSS Twitter (10)
RSS Video (20)
RSS Webcam (3)
RSS Writing (10)

Blogs I Read

 
Terrence Ryan
Ben Forta
Ray Camden
Kinky Solutions
Dan Vega
Gary Gilbert
Simeon Bateman
Red Hat Blogs
O'Reilly Digital Media
O'Reilly Radar
John Nack
The Strobist
Scott Kelby
Matt Kloskowski
Joe McNally
Digital Photography School
Engadget
Science Blog

RSS

 


Add to Google
Add to My Yahoo!

Aggregated By

 


Consumed By Feed-Squirrel.com
Aggregated by ColdFusionBlogger.org

Credits and Stuff

 
BlogCFC - Free ColdFusion Powered Blog Software
CJM Group - ColdFusion Website Hosting


 
 
blog | photos | flickr | referers | webcam | stats | about | contact
 
Copyright © 2010 Steven Erat. All rights reserved.
This is a personal weblog. The opinions expressed here represent my own and not those of my employer