Newbie: best way to connect to MySQL?

Hi All,

I’m teaching myself Ruby, and thus far I’ve managed to successfully
attach to and INSERT / SELECT / etc records from a MSSQL server using
the ODBC driver. I’ve been trying to do the same thing with a MySQL
server, using MyODBC set up to connect to the server and database in
question, but whenever I try to then run code against that server I
get an error message.

The code I’m using is:

require “odbc”

conn = ODBC::connect(‘MySQLPitOfDespair’)

The error message I’m getting is:

2007-03-13_ConnectMySQLODBC.rb:3:in initialize': S1000 (1045) [MySQL] [ODBC 3.51 Driver]Access denied for user 'ODBC'@'localhost' (using password: NO) (ODBC::Error) from 2007-03-13_ConnectMySQLODBC.rb:3:inconnect’
from 2007-03-13_ConnectMySQLODBC.rb:3

I’m reasonably certain that I’ve created the ODBC connection
correctly, since I can link tables from the MySQL server into a
Microsoft Access database using the ODBC DSN of ‘MySQLPitOfDespair’.

Is there a better way to connect to a MySQL server using Ruby than via
ODBC? Is there a syntax for supplying user and password settings for
the ODBC::connect statement above?

Many thanks for any help!

pt

On Mar 12, 4:33 pm, “planetthoughtful” [email protected]
wrote:

Is there a better way to connect to a MySQL server using Ruby than via
ODBC? Is there a syntax for supplying user and password settings for
the ODBC::connect statement above?

Yes, use the mysql gem.

install:
gem install mysql

“planetthoughtful” [email protected] writes:

install:

  • Can I download the gem file?
    Yes,you can.
  • Is there any special syntax for installing it from a local file?
    No,just place the file *.gem under the current dir,then execute
    “gem i filename.gem”

Thanks again!

pt


http://kdr2.net

                                           ------yours Killy Draw

On Mar 13, 10:33 am, “kreiggers” [email protected] wrote:

gem install mysql
Hi,

Thanks for your reply. Do you (or does anyone else) know if I can
download and install the mysql gem locally? I’m behind a corporate
firewall and it doesn’t seem that the Gem package manager can get out.

So, I guess what I’m asking is:

  • Can I download the gem file?
  • Where do I get it from, if I can?
  • Is there any special syntax for installing it from a local file?

Thanks again!

pt

On Mar 12, 6:43 pm, KDr2 [email protected] wrote:

“planetthoughtful” [email protected] writes:

On Mar 13, 10:33 am, “kreiggers” [email protected] wrote:

On Mar 12, 4:33 pm, “planetthoughtful” [email protected]
wrote:

Is there a better way to connect to a MySQL server using Ruby than via
ODBC? Is there a syntax for supplying user and password settings for
the ODBC::connect statement above?

Personally, I like using ActiveRecord to connect to databases. For
basic database manipulation, it’s a lot easier to use than straight up
SQL, especially if your databases are configured the way AR wants them
to be. If not, then there’s some annoying setup work with set_* and
joins that might be more hassle than it’s worth, depending on what
you’re doing.

Download here:
http://rubyforge.org/projects/activerecord/

Documentation here:
http://ar.rubyonrails.org/

–Alpha Chen

On Mar 12, 6:43 pm, KDr2 [email protected] wrote:

“planetthoughtful” [email protected] writes:

On Mar 13, 10:33 am, “kreiggers” [email protected] wrote:

On Mar 12, 4:33 pm, “planetthoughtful” [email protected]
wrote:

Is there a better way to connect to a MySQL server using Ruby than via
ODBC? Is there a syntax for supplying user and password settings for
the ODBC::connect statement above?

Personally, I like using ActiveRecord to connect to databases. For
basic database manipulation, it’s a lot easier to use than straight up
SQL, especially if your databases are configured the way AR wants them
to be. If not, then there’s some annoying setup work with set_* and
joins that might be more hassle than it’s worth, depending on what
you’re doing.

Download here:
http://rubyforge.org/projects/activerecord/

Documentation here:
http://ar.rubyonrails.org/

–Alpha Chen

On Mar 13, 11:43 am, KDr2 [email protected] wrote:

  • Where do I get it from, if I can?

there are many sites…for eg:http://rubyforge.vm.bytemark.co.uk/gems/

  • Is there any special syntax for installing it from a local file?

No,just place the file *.gem under the current dir,then execute
“gem i filename.gem”

Hi - just wanted say thank you for your help with this! I’m not sure
what was wrong with my Google-Fu, but I’d spent a couple of hours
trying to find somewhere from which I could download gem files
directly without any luck.

Now happily connecting to MySQL!

Thanks again!

pt

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