Working with mysql in ruby

i have been trying to successfully connect ruby with mysql. there are a
hundred examples with code and some using different gems.
gems i have tried:
mysql
mysql2
dbi
ruby-mysql

the code examples i have found have been pretty much the same so im
guessing its something with the gems, maybe they are not installing
right, i tried moving them around to different files but it didnt make a
difference.

i have also read that mysql gem is not supported…so i want to start
with a question before i post any code or ask for any code,

does anyone know of a ruby-mysql gem that they have gotten to work, (by
work i mean connect to mysql database, and interact with mysql through
ruby)

On Thu, Nov 22, 2012 at 6:33 AM, john smith [email protected]
wrote:

does anyone know of a ruby-mysql gem that they have gotten to work, (by
work i mean connect to mysql database, and interact with mysql through
ruby)

Absolutely; the mysql2 gem works fine standalone, or as part of a
high percentage of current Rails apps.

If you’re having problems, post your code and the error message(s).

Hi John,

On 23/11/12 01:03, john smith wrote:

does anyone know of a ruby-mysql gem that they have gotten to work, (by
work i mean connect to mysql database, and interact with mysql through
ruby)

I can’t speak for MySQL, but I’ve been using DBI with a PostgreSQL
database for a project with simple database needs, and after the initial
setup it has been fairly low-hassle to use. If I had to talk to a MySQL
database at this point I’d try DBI first, but that’s just me, and it
could be bad advice.

As a point of reference, I’m using DBI 0.4.5 with Ruby 1.9.2 p136 at
present on this project.

I hope this is of some use.

Cheers,
Garth

Here is the error i get:

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require': cannot load such fil e -- mysql (LoadError) from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire’
from C:/Users/will/Notepad++/Databases/ruby_DBI.rb:11:in
`’

Here is my code:

require ‘rubygems’
require ‘mysql’

begin
connect = Mysql.new ‘root’, ‘user12’, ‘34klq*’
puts connect.get_server_info
rs = connect.query ‘SELECT VERSION()’
puts rs.fetch_row

rescue Mysql::Error => e
puts e.errno
puts e.error

ensure
connect.close if connect
end

This is the same type of problem i get no matter what gem i use or
tutorial i follow. any help please.

here is another attempt…

code:

require ‘mysql’

begin
dbh = Mysql.new(‘root’, ‘user12’, ‘34klq*’, ‘mydb’)
puts dbh.get_server_info
rs = dbh.query’SELECT VERSION()’
puts rs.fetch_row

ensure
dbh.close if dbh
end

Result:

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
require': cannot load such fil e -- mysql (LoadError) from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire’
from C:/Users/will/Notepad++/Databases/ruby_DBI.rb:1:in `’

Any help would be appreciated thank you

I just tried reinstalling ruby, i installed the devkit. i do have vmware
with ubuntu and bt5 that i could use, but im more comfortable with
windows. do you know of any other database that works well with ruby
that i could try?

On Sun, Nov 25, 2012 at 9:34 AM, john smith [email protected]
wrote:

here is another attempt…

OK, stop right there –

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require’: cannot load such file – mysql (LoadError)

You say this same thing happens with any gem; that means your
ruby/rubygems installation is broken. Unfortunately I have no idea
how to troubleshoot that on Windows.

You might try re-installing from scratch. Or just sidestep the pain and
install a VM with some Linux distro. :slight_smile:

Otherwise, perhaps someone with Windows experience will be able
to suggest something. Sorry.

На 25.11.2012 г. 20:39 ч., john smith написа:

I just tried reinstalling ruby, i installed the devkit. i do have vmware
with ubuntu and bt5 that i could use, but im more comfortable with
windows. do you know of any other database that works well with ruby
that i could try?

I don’t understand Ruby, nevertheless I installed Redmine in our office.
So,
when we moved to Ruby 1.9.3 I had to use mysql2 gem, not mysql. My
advice is
to try mysql2.
mysql2 requires newer version of libmysql.dll (6.0.2)


Regards,

Ivan Cenov
OKTO-7 Co. Bulgaria
[email protected], [email protected]
mobile:+359888761080,
phone:+35972366161, fax:+_35972366262

On Sun, Nov 25, 2012 at 10:39 AM, john smith [email protected]
wrote:

I just tried reinstalling ruby, i installed the devkit. i do have vmware
with ubuntu and bt5 that i could use, but im more comfortable with
windows. do you know of any other database that works well with ruby
that i could try?

This has nothing whatsoever to do with a particular DB. MySQL
with the mysql or mysql2 gem works fine “with ruby”.

It’s the fact that your program can’t find the gem in the first place
that you need to address.

I will try to figure out the issue with the gem not being found, i read
a page a while ago about different ways to install the gem…i think
with a -r switch or something ill see if i can find that again and
reinstall and see if that does anything.

Do you see anything wrong with the code its self?

Ivan Cenov wrote in post #1086301:

На 25.11.2012 г. 20:39 ч., john smith написа:

I just tried reinstalling ruby, i installed the devkit. i do have vmware
with ubuntu and bt5 that i could use, but im more comfortable with
windows. do you know of any other database that works well with ruby
that i could try?

I don’t understand Ruby, nevertheless I installed Redmine in our office.
So,
when we moved to Ruby 1.9.3 I had to use mysql2 gem, not mysql. My
advice is
to try mysql2.
mysql2 requires newer version of libmysql.dll (6.0.2)


Regards,

Ivan Cenov
OKTO-7 Co. Bulgaria
[email protected], [email protected]
mobile:+359888761080,
phone:+35972366161, fax:+_35972366262

It was the libmysql.dll file, when you d/l the mysql 2.9.0 it said:

You’ve installed the binary version of mysql.
It was built using MySQL Connector/C version 6.0.2.
It’s recommended to use the exact same version to avoid potential
issues.

At the time of building this gem, the necessary DLL files where
available
in the following URL:

http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pi
ck

You can put the lib\libmysql.dll available in this package to your
Ruby bin directory.
E.g. C:\Ruby\bin

Go to website unzip and place the libmysql.dll file in your ruby/bin
folder. thanks for all the help

I would suggest you to install the rails installer since it’s installing
anything you need on windows.
this link:
http://rubyforge.org/frs/download.php/75894/railsinstaller-2.1.0.exe

is not working for me couple days already so try this one:
http://ruby.taobao.org/mirrors/ruby/railsinstaller/railsinstaller-2.1.0.exe

Eliezer

You can put the lib\libmysql.dll available in this package to your
Ruby bin directory.
E.g. C:\Ruby\bin

Go to website unzip and place the libmysql.dll file in your ruby/bin
folder. thanks for all the help

Don’t forget that you’ve got the RubyInstaller group as a resource if
you’re not getting decent windows specific answers here.

Here’s the search results with “mysql”.

https://groups.google.com/forum/?fromgroups#!searchin/rubyinstaller/mysql

Also, briefly describe your system when posting. No one knew you were
trying to use mysql on a windows system or your ruby version.

Jon

Please unsubscribe me from this list. Thanks!

Jon F. wrote in post #1086333:

You can put the lib\libmysql.dll available in this package to your
Ruby bin directory.
E.g. C:\Ruby\bin

Go to website unzip and place the libmysql.dll file in your ruby/bin
folder. thanks for all the help

Don’t forget that you’ve got the RubyInstaller group as a resource if
you’re not getting decent windows specific answers here.

Here’s the search results with “mysql”.

https://groups.google.com/forum/?fromgroups#!searchin/rubyinstaller/mysql

Also, briefly describe your system when posting. No one knew you were
trying to use mysql on a windows system or your ruby version.

Jon

I will remember to mention my system and ruby version next time. thank
you.

Thanks Arlen!

Travis

Only you can do that:
http://www.ruby-lang.org/en/community/mailing-lists/#subscriptions-form

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs