Are you deploying your JRuby-on-Rails applications on Solaris (or any variety of Unix) and not able to connect to the database ?
I experienced it last week so thought of sharing the tip here. Luckily it’s really simple.
Here is the default generated “config/database.yml”
| development: adapter: mysql encoding: utf8 database: runner_development username: root password: socket: /tmp/mysql.sock |
The only required change is to add “host: 127.0.01″ for the required database configuration. The updated fragment is shown below (with change highlighted):
| development: adapter: mysql encoding: utf8 database: runner_development username: root password: socket: /tmp/mysql.sock host: 127.0.01 |
Even though “host” is required for TCP connections but the database connection does not seem to work without this entry. The exact same application works without “host” entry on Windows and Mac OS.
Alternatively, you can always install the JDBC adapter as explained here.
Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. A complete archive is available here.
Technorati: totd rubyonrails jruby ruby opensolaris mysql
Related posts:- TOTD #3: Using JavaDB with JRuby on Rails
- TOTD #81: How to configure “database.yml” to be used with both JRuby and MRI ?
- TOTD #9: Using JDBC connection pool/JNDI name from GlassFish in Rails Application
- ActiveRecord-JDBC 0.5 – simplified database configuration
- TOTD #70: JRuby and GlassFish Integration Test# 1: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish Gem
Basically you don’t need
’socket: /tmp/mysql.sock’
socket or host are mmutually exclusive, looks like if host entry is there it takes over socket.
Looks like there is some bug with handling unix domain socket, use -J-Djruby.native.enabled=false on the jruby CLI and you wont see any issue. See a thread on this atusers@jruby[1].
[1]http://markmail.org/search/list:org.codehaus.jruby?q=vivek+pandey#query:vivek%20pandey+page:1+mid:6d6rn6v2mlfrhzcs+state:results
Comment by vivek — June 23, 2008 @ 9:54 am
[Trackback] My primary development machine is Mac OS Leopard on Intel Core 2 Duo (read osxtips). But the beauty of virtualization is that I can run multiple Operating Systems on a single powerful machine. And what better virtualization product than…
Comment by Arun Gupta's Blog — June 24, 2008 @ 6:22 am
One other step I needed was to add my port info. For instance:
development:
adapter: mysql
encoding: utf8
database: my_db_name_here
username: root
password: root
host: 127.0.0.1
port: 8889
Am running MySQL as part of the MAMP bundle; am guessing my port isn’t the default.
Cheers,
Bobby
Comment by Bobby Bissett — August 21, 2008 @ 11:41 am