Cannot load such file -- mysql (LoadError)

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’

bumps

You need to find out how to use the library by reading the docs, for
example:
https://github.com/brianmario/mysql2

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

Robert H. 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. :slight_smile:

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

Ronald F. 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-rubygems-is-wrong-1478.html

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-while-connecting-to-mysql-using-ruby

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-rubygems-is-wrong-1478.html

Ronald F. 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.

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.

Ronald F. wrote in post #1185098:

Peter C. 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.

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.

Ronald F. 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?

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.

Peter C. is also using mysql2?

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.

Ronald F. wrote in post #1185110:

Suresh Ilankovan wrote in post #1185106:

Ronald F. 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

Suresh Ilankovan wrote in post #1185106:

Ronald F. 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”?

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???

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