Forum: Ruby working with mysql in ruby

Posted by john smith (pegasus300)
on 2012-11-22 15:33
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)
Posted by Hassan Schroeder (Guest)
on 2012-11-22 17:25
(Received via mailing list)
On Thu, Nov 22, 2012 at 6:33 AM, john smith <lists@ruby-forum.com> 
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).
Posted by Garthy D (Guest)
on 2012-11-23 01:28
(Received via mailing list)
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
Posted by john smith (pegasus300)
on 2012-11-23 19:53
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:in 
`require'
        from C:/Users/will/Notepad++/Databases/ruby_DBI.rb:11:in 
`<main>'


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.
Posted by john smith (pegasus300)
on 2012-11-25 18:34
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:in 
`require'
        from C:/Users/will/Notepad++/Databases/ruby_DBI.rb:1:in `<main>'

Any help would be appreciated thank you
Posted by Hassan Schroeder (Guest)
on 2012-11-25 19:24
(Received via mailing list)
On Sun, Nov 25, 2012 at 9:34 AM, john smith <lists@ruby-forum.com> 
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.  :-)

Otherwise, perhaps someone with Windows experience will be able
to suggest something. Sorry.
Posted by john smith (pegasus300)
on 2012-11-25 19:39
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?
Posted by Ivan Cenov (jwalker)
on 2012-11-25 19:55
(Received via mailing list)
На 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
imc@okto7.com, i_cenov@botevgrad.com
mobile:+359888761080,
phone:+35972366161, fax:+_35972366262
Posted by Hassan Schroeder (Guest)
on 2012-11-25 20:13
(Received via mailing list)
On Sun, Nov 25, 2012 at 10:39 AM, john smith <lists@ruby-forum.com> 
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.
Posted by john smith (pegasus300)
on 2012-11-25 20:38
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?
Posted by john smith (pegasus300)
on 2012-11-25 21:24
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
> imc@okto7.com, i_cenov@botevgrad.com
> 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/mys...
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
Posted by Eliezer Croitoru (Guest)
on 2012-11-25 23:57
(Received via mailing list)
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/railsi...

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

Eliezer
Posted by Jon Forums (jonm)
on 2012-11-26 00:14
>   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#!searc...

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
Posted by john smith (pegasus300)
on 2012-11-26 01:26
Jon Forums 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#!searc...
>
> 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.
Posted by Travis Johnson (Guest)
on 2012-11-26 02:04
(Received via mailing list)
Please unsubscribe me from this list. Thanks!
Posted by Arlen Cuss (unnali)
on 2012-11-26 02:05
(Received via mailing list)
Posted by Travis Johnson (Guest)
on 2012-11-26 05:47
(Received via mailing list)
Thanks Arlen!

Travis
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.