# Mysql driver question

**URL:** <https://www.ruby-forum.com/t/mysql-driver-question/85948>\
**Category:** Deployment\
**Created:** [February 18, 2007, 1:48am UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948 "2007-02-18T01:48:44Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [February 18, 2007, 1:48am UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/1 "2007-02-18T01:48:44Z")

</div>

I asked my hosting service whether they were using the native ruby mysql  
driver or the compiled version and they responded with “We use Ruby  
gems”. Does that mean they use the native ruby driver? I don’t know  
enough about the architecture to know whether the gem is the driver, or  
just the api to the driver.

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [February 18, 2007, 1:52am UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/2 "2007-02-18T01:52:44Z")

</div>

Hi~

On Feb 17, 2007, at 4:48 PM, Bill W. wrote:

> I asked my hosting service whether they were using the native ruby  
> mysql driver or the compiled version and they responded with “We  
> use Ruby gems”. Does that mean they use the native ruby driver? I  
> don’t know enough about the architecture to know whether the gem is  
> the driver, or just the api to the driver.
> 
> Thanks,  
> Bill

The “mysql” gem is the native C bindings.

– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [February 18, 2007, 1:53am UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/3 "2007-02-18T01:53:44Z")

</div>

On Feb 17, 2007, at 4:48 PM, Bill W. wrote:

> I asked my hosting service whether they were using the native ruby  
> mysql driver or the compiled version and they responded with “We  
> use Ruby gems”. Does that mean they use the native ruby driver? I  
> don’t know enough about the architecture to know whether the gem is  
> the driver, or just the api to the driver.
> 
> Thanks,  
> Bill

Also if your host is running linux then you can tell for sure if  
it’s the compiled driver from irb:

ey00-s00059 ~ # irb  
irb(main):001:0\> require ‘mysql.so’  
=\> true

cheers-

– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [February 18, 2007, 2:09am UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/4 "2007-02-18T02:09:45Z")

</div>

Hi Ezra,

Ezra Z. wrote:

> Also if your host is running linux then you  
> can tell for sure if it’s the compiled driver  
> from irb:
> 
> ey00-s00059 ~ # irb  
> irb(main):001:0\> require ‘mysql.so’  
> =\> true

That was just what I needed to know. Here’s what happens.

When I run ‘gem list’ the list includes:  
mysql (2.7)

BUT …

removed\_email\_address@domain.invalid [~/emrec]# irb  
irb(main):001:0\> require ‘mysql.so’  
LoadError: no such file to load – mysql.so  
from (irb):1:in `require’  
from (irb):1  
irb(main):002:0\>

What’s it mean?

Thanks!  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [February 18, 2007, 1:58am UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/5 "2007-02-18T01:58:44Z")

</div>

Thanks, Ezra!

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [February 18, 2007, 1:57pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/6 "2007-02-18T13:57:26Z")

</div>

Ezra,

```
As I undertand the ruby-mysql library 2.7 does require the

```

libmysqlclient to be properly installed, and depending on the location  
of mysql.so it is possible that rubygems is unable to load it, while  
the library is actually using it…

–  
Anibal Rojas

> **[RUBYCORNER.COM](https://www.rubycorner.com/)**
>
> RUBYCORNER.COM - Contact us for any business inquiries

> **[Home - Has Many Developers](https://hasmanydevelopers.com/)**
>
> We are the best choice for your building design and development

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [February 18, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/7 "2007-02-18T16:30:41Z")

</div>

Hi Anibal,

Thank you for joining the thread. A follow-on question below.

Aníbal Rojas wrote:

> As I undertand the ruby-mysql library 2.7 does require the  
> libmysqlclient to be properly installed, and depending on  
> the location of mysql.so it is possible that rubygems is unable  
> to load it, while the library is actually using it…

I’ve had other problems with this environment and its beginning to feel  
like  
maybe they’re all symptoms of one underlying, probably simple, cause.

The first involved BackgroundRb. Even though I had the line in  
environment.rb uncommented to set RAILS\_ENV to production, BackgroundRb  
was  
not picking it up and was writing the record of database access that I  
do in  
my worker to development.log. Invoking BackgroundRb with  
‘RAILS\_ENV=production /script/backgroundrb/start -d’ corrected that.  
But  
I’m still concerned because I have no idea why the behavior occurred in  
the  
first place.

Is it possible the two behaviors are both related to some underlying  
problem?

Thanks!  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [March 22, 2007, 11:42am UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/8 "2007-03-22T11:42:04Z")

</div>

Hi

I have the same problem, ie gem reports mysql (2.7) installed but irb  
cannot find ‘mysql.so’, ie:

[root@heliosintranet ~]# irb  
irb(main):001:0\> require ‘mysql.so’  
LoadError: libmysqlclient.so.15: cannot open shared object file: No such  
file or directory - /usr/lib/ruby/site\_ruby/1.8/i386-linux/mysql.so  
from /usr/lib/ruby/site\_ruby/1.8/i386-linux/mysql.so  
from (irb):1

The odd thing is that “/usr/lib/ruby/site\_ruby/1.8/i386-linux/mysql.so”  
is present!

Why can’t it be found? Any ideas?

Thanks  
Nick

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [March 22, 2007, 5:46pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/9 "2007-03-22T17:46:25Z")

</div>

Hi aurelian,

Thanks for replying. I tried that but got some strange results…

I added the following to .bash\_login

export  
LD\_LIBARY\_PATH=/usr/local/mysql5/lib/mysql/libmysqclient.so:$LD\_LIBRARY\_PATH

I then tested it with

> sh .bash\_login

> $LD\_LIBARY\_PATH

I get the error:

> /usr/local/mysql5/lib/mysql/libmysqlclient.so:: No such file or directory

And the irb \> require ‘mysql.so’ still doesn’t work.

(As an aside, the file libmysqlclient.so is actually a link to  
libmysqlclient.so.15.0.0 in the same directory.)

Any ideas what is going on?

Thanks alot for your help  
Nick

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [March 22, 2007, 4:12pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/10 "2007-03-22T16:12:47Z")

</div>

Hello,

On 3/22/07, Nick McFarlane wrote:

> ```
> from /usr/lib/ruby/site_ruby/1.8/i386-linux/mysql.so
> from (irb):1
> 
> ```
> 
> The odd thing is that “/usr/lib/ruby/site\_ruby/1.8/i386-linux/mysql.so”  
> is present!
> 
> Why can’t it be found? Any ideas?

I had the same issue, and the error states that mysql.so cannot find  
libmysqlclient.so.

To fix it, make sure you have libmysqlclient.so on your system and  
that the path to it is in your LD\_LIBRARY\_PATH environment variable.

So I had to add:

export LD\_LIBRARY\_PATH=/W/lib:$LD\_LIBRARY\_PATH

in my .bash\_login

/W/lib is the folder that contains libmysqlclient.so

> Thanks  
> Nick

–  
Aurelian

Web: [http://www.locknet.ro](http://www.locknet.ro)

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [March 22, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/11 "2007-03-22T18:40:04Z")

</div>

OK, I’m not the sharpest tool in the box!!

That should have been:  
export LD\_LIBRARY\_PATH=/usr/local/mysql5/lib/mysql:$LD\_LIBRARY\_PATH

I added it to /etc/profile and /etc/bashrc (just to be sure) on my  
deployment machine.

So now this bit works:

> irb  
> require ‘mysql.so’  
> =\> true

but the application doesn’t. I still get this error in production.log:

RuntimeError (Mysql not loaded):  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/connection\_adapters/mysql\_adapter.rb:7:in  
`define_all_hashes_method!' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/connection_adapters/mysql_adapter.rb:60:in`require\_mysql’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/connection\_adapters/mysql\_adapter.rb:78:in  
`mysql\_connection’  
…

Does this mean that the path command worked for me but not gem?

Thanks  
Nick

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [March 22, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/12 "2007-03-22T20:51:20Z")

</div>

Hi,

Try to execute:

export LD\_LIBRARY\_PATH=/usr/local/mysql5/lib:$LD\_LIBRARY\_PATH

Other that this, I don’t have any other suggestion for you 🙂

And yes, you are right, on linux it should be probably added to  
/etc/profile or ~/.bash\_profile.

On 3/22/07, Nick McFarlane [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > irb  
> > /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/connection\_adapters/mysql\_adapter.rb:78:in  
> > `mysql\_connection’  
> > …
> 
> Does this mean that the path command worked for me but not gem?

Strange…

> Thanks  
> Nick

–  
Aurelian

Web: [http://www.locknet.ro](http://www.locknet.ro)

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [March 23, 2007, 11:24pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/13 "2007-03-23T23:24:29Z")

</div>

aurelian wrote:

> Hi,
> 
> Try to execute:
> 
> export LD\_LIBRARY\_PATH=/usr/local/mysql5/lib:$LD\_LIBRARY\_PATH
> 
> Other that this, I don’t have any other suggestion for you 🙂
> 
> And yes, you are right, on linux it should be probably added to  
> /etc/profile or ~/.bash\_profile.

On linux, you should really add it to /etc/ld.so.conf (or in  
/etc/ld.so.conf.d if your distro supports it) and run ‘ldconfig’ – that  
sets it system-wide. See crle on Solaris for similar functionality.

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [March 26, 2007, 12:24pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/14 "2007-03-26T12:24:52Z")

</div>

> On linux, you should really add it to /etc/ld.so.conf (or in  
> /etc/ld.so.conf.d if your distro supports it) and run ‘ldconfig’ – that  
> sets it system-wide. See crle on Solaris for similar functionality.

Ben  
Thanks for this.

The previous suggestion with didn’t work since SUDO removes path  
variables. But I’d like to try your suggestion. For now I have some  
changes in deploy.rb to set the path:

task :start\_mongrel\_cluster , :roles =\> :app do  
set\_mongrel\_conf  
send(run\_method, "sh -c ’  
LD\_LIBRARY\_PATH=/usr/local/mysql5/lib/mysql;  
export LD\_LIBRARY\_PATH;  
mongrel\_rails cluster::start -C #{mongrel\_conf}  
’  
")  
end

task :restart\_mongrel\_cluster , :roles =\> :app do  
set\_mongrel\_conf  
send(run\_method, "sh -c ’  
LD\_LIBRARY\_PATH=/usr/local/mysql5/lib/mysql;  
export LD\_LIBRARY\_PATH;  
mongrel\_rails cluster::restart -C #{mongrel\_conf}  
’  
")  
end

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [March 28, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/15 "2007-03-28T16:58:10Z")

</div>

By default, gem installs a win32-native version of the mysql driver  
(2.7.3 atm), so if you are running on linux… native calls won’t work

uninstall any mysql adapter you may have with :

> gem uninstall mysql

install version 2.7

> gem install ruby

you are then prompted to choose version to install, choose 2.7 (ruby)

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [March 28, 2007, 5:00pm UTC](https://www.ruby-forum.com/t/mysql-driver-question/85948/16 "2007-03-28T17:00:11Z")

</div>

I meant \> gem install mysql

sry
