Forum: Ruby cannot load such file -- mysql (LoadError)

Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-23 14:48
Anyone manage to solve this error?

i simply did install gem install mysql.
When i try running the code it shows that error.
I tried to download libmySQL.dll and placed the file at the lib folder
for mysql still it doesn't seem to work.

ps i did both the following as well but did not work.


require 'rubygems'
require 'mysql'


require_relative 'rubygems'
require_relative 'mysql'
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-25 16:26
bumps
6c7fb11d4f3fa354a51a3ea0375d895f?d=identicon&s=25 Joe Gain (timeout)
on 2016-09-26 08:31
You need to find out how to use the library by reading the docs, for
example:
https://github.com/brianmario/mysql2
4828d528e2e46f7c8160c336eb332836?d=identicon&s=25 Robert Heiler (shevegen)
on 2016-09-28 09:30
Are you perhaps on windows?

The above works for me on linux, for instance.

    gem install mysql2

Fetching: mysql2-0.4.4.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql2-0.4.4
Parsing documentation for mysql2-0.4.4
Installing ri documentation for mysql2-0.4.4
Done installing documentation for mysql2 after 2 seconds
1 gem installed


The name for that is mysql2 though. I am not sure which
mysql variant you try - for mysql2 it works for me:

  require 'mysql2'  # => true

Always try to add the information how you installed something
and what your operating system is too. And your ruby version. :)
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-28 17:28
Robert Heiler wrote in post #1185084:
> Are you perhaps on windows?
>
> The above works for me on linux, for instance.
>
>     gem install mysql2
>
> Fetching: mysql2-0.4.4.gem (100%)
> Building native extensions.  This could take a while...
> Successfully installed mysql2-0.4.4
> Parsing documentation for mysql2-0.4.4
> Installing ri documentation for mysql2-0.4.4
> Done installing documentation for mysql2 after 2 seconds
> 1 gem installed
>
>
> The name for that is mysql2 though. I am not sure which
> mysql variant you try - for mysql2 it works for me:
>
>   require 'mysql2'  # => true
>
> Always try to add the information how you installed something
> and what your operating system is too. And your ruby version. :)

Thanks alot bro. I am using RubyMine software with version 2.2.
I always face with this issue whenever i use the require. it's like
whenever i use require the error always pops up. i tried to google can't
find it though. and i used mysql2 still doesn't work for me
Btw i am using Windows 10
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-09-29 11:26
Why are you doing a

    require 'rubygems'

? I never did it (simply because I didn't know that you *can* do it),
but after seeing your post, I googled, and found the following article,
which might be of interest to you:

http://www.rubyinside.com/why-using-require-rubyge...
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-29 15:00
Ronald Fischer wrote in post #1185089:
> Why are you doing a
>
>     require 'rubygems'
>
> ? I never did it (simply because I didn't know that you *can* do it),
> but after seeing your post, I googled, and found the following article,
> which might be of interest to you:
>
> http://www.rubyinside.com/why-using-require-rubyge...

Below is my code:
------------------------------------------
require 'mysql2'
db = Mysql2.connect('localhost','root','','test')

#Perform an arbitrary SQL query
db.query("INSERT INTO people(name,age)VALUES('Chris',25")

#Perform a query that return data
begin
   query = db.query('SELECT * FROM people')
   puts "There were #{query.num_rows} rows returned"

query.each_hash do |h|
   puts h.inspect
end
rescue
 puts db.errno
 puts db.error
end

#Close the connection cleanly
db.close
--------------------------------------------

Now i installed mysql2 then...
Now the errors prompts with this:
undefined method `connect' for Mysql2:Module (NoMethodError)

i have tried installing pure ruby sql which is ruby-mysql
i also tried using real_connect. I did refer to this website though:
http://stackoverflow.com/questions/2591794/issues-...
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-09-29 15:14
Okay, so you *can* load the module, and you are facing a completely
different problem: There is no module method Mysql2.

Now I don't know this module and can not tell you how to use it, but a
quick look at http://www.rubydoc.info/gems/mysql2/0.3.11/Mysql2 (click
on the link "Methods" near the top left corner) shows that there is
indeed not method named connect. May I ask you where you got the idea
from, that such a method might exist? When you read

http://www.rubydoc.info/gems/mysql2/0.3.11/frames

you will find that the usage pattern of the module looks quiet
differently from what you are doing.
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-29 15:27
Ronald Fischer wrote in post #1185096:
> Okay, so you *can* load the module, and you are facing a completely
> different problem: There is no module method Mysql2.
>
> Now I don't know this module and can not tell you how to use it, but a
> quick look at http://www.rubydoc.info/gems/mysql2/0.3.11/Mysql2 (click
> on the link "Methods" near the top left corner) shows that there is
> indeed not method named connect. May I ask you where you got the idea
> from, that such a method might exist? When you read
>
> http://www.rubydoc.info/gems/mysql2/0.3.11/frames
>
> you will find that the usage pattern of the module looks quiet
> differently from what you are doing.

i now reading the peter cooper book. i am following exactly what he did.
Ya it's like quite different from what you send me the link compared to
what i am doing with the book.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-09-29 15:55
Peter Cooper is also using mysql2?
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-29 15:58
Ronald Fischer wrote in post #1185098:
> Peter Cooper is also using mysql2?

He's using mysql. but it didn't work on my RubyMine version 2.2. that's
why i also not sure of this problem.
whenever he mention the using the require thing. my first instinct
always telling me sure have error.
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-29 16:00
Suresh Ilankovan wrote in post #1185099:
> Ronald Fischer wrote in post #1185098:
>> Peter Cooper is also using mysql2?
>
> He's using mysql. but it didn't work on my RubyMine version 2.2. that's
> why i also not sure of this problem.


whenever he mention the using the require thing. my first instinct
always telling me sure have error.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-09-29 18:00
Well, if he is using a different gem, it is quite obvious that the
interface might be different.

If you want to stick verbatim with the book, you should use mysql.
Otherwise, you use mysql2.
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-30 04:11
Ronald Fischer wrote in post #1185102:
> Well, if he is using a different gem, it is quite obvious that the
> interface might be different.
>
> If you want to stick verbatim with the book, you should use mysql.
> Otherwise, you use mysql2.

Should i use Textmate instead through out the book?
6c7fb11d4f3fa354a51a3ea0375d895f?d=identicon&s=25 Joe Gain (timeout)
on 2016-09-30 07:52
Suresh,

instead of just following the book you need to think about the
"conceptual" steps that are being taken. Often, the names of the
functions will help you.

In this case, you have two pretty clear choices: you work with the mysql
gem, which is 5+ years old but which is used in the book, or you try to
find out how to do what you want with the newer gem.

It's not very complicated what you want to do because all you want to do
at the moment is
1. connect to the database
2. submit queries

You can test this process by using the database from the command line
(although often the connection process is done automatically from the
command line as it may be part of configuring the "database".)

If you look at the first example on the github page for mysql2 it gives
you some idea about how to do it, but google will always help you find
more examples and answers to problems.

If you can't get mysql or mariadb to work, try using sqlite. You may
find it generally more easier to use ruby with a unix operating system
but I can't really comment on this because I don't use windows.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-09-30 09:24
Suresh Ilankovan wrote in post #1185106:
> Ronald Fischer wrote in post #1185102:
> Should i use Textmate instead through out the book?

I don't understand what you want to say. I only know "Textmate" being a
texteditor for the Mac (http://macromates.com/download), but this  would
make no sense in your case. So, what do you mean by "Textmate"?
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-30 12:42
Joe Gain wrote in post #1185107:
> Suresh,
>
> instead of just following the book you need to think about the
> "conceptual" steps that are being taken. Often, the names of the
> functions will help you.
>
> In this case, you have two pretty clear choices: you work with the mysql
> gem, which is 5+ years old but which is used in the book, or you try to
> find out how to do what you want with the newer gem.
>
> It's not very complicated what you want to do because all you want to do
> at the moment is
> 1. connect to the database
> 2. submit queries
>
> You can test this process by using the database from the command line
> (although often the connection process is done automatically from the
> command line as it may be part of configuring the "database".)
>
> If you look at the first example on the github page for mysql2 it gives
> you some idea about how to do it, but google will always help you find
> more examples and answers to problems.
>
> If you can't get mysql or mariadb to work, try using sqlite. You may
> find it generally more easier to use ruby with a unix operating system
> but I can't really comment on this because I don't use windows.


Ok i will try using other ways.

Thanks bro.
Be955f2578b8971802ceab589fe24ad3?d=identicon&s=25 Suresh Ilankovan (sureshhey)
on 2016-09-30 12:42
Ronald Fischer wrote in post #1185110:
> Suresh Ilankovan wrote in post #1185106:
>> Ronald Fischer wrote in post #1185102:
>> Should i use Textmate instead through out the book?
>
> I don't understand what you want to say. I only know "Textmate" being a
> texteditor for the Mac (http://macromates.com/download), but this  would
> make no sense in your case. So, what do you mean by "Textmate"?

Ya i was referring to TextMate
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-10-03 10:07
Suresh Ilankovan wrote in post #1185113:
> Ya i was referring to TextMate

Then I don't understand. How is your choice of a text editor related to
how you solve a programming problem????
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.