Newbie: best way to connect to MySQL?

P

planetthoughtful

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:in `connect'
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
 
K

kreiggers

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
 
P

planetthoughtful

Yes, use the mysql gem.

install:
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
 
K

KDr2

planetthoughtful said:
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?
Yes,you can.
- 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"
 
A

alpha.chen

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
 
P

planetthoughtful

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


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
 
A

alpha.chen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top