Mysql driver question

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

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
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

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
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

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 …

[email protected] [~/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

Thanks, Ezra!

Best regards,
Bill

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

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

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

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

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

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:inrequire_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

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 :slight_smile:

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

On 3/22/07, Nick McFarlane [email protected] 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

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 :slight_smile:

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.

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

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)

I meant > gem install mysql

sry