[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie: best way to connect to MySQL?

M Wells

3/12/2007 11:33:00 PM

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

6 Answers

kreiggers

3/13/2007 12:34:00 AM

0

On Mar 12, 4:33 pm, "planetthoughtful" <planetthought...@gmail.com>
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





M Wells

3/13/2007 12:58:00 AM

0

On Mar 13, 10:33 am, "kreiggers" <luckybo...@gmail.com> wrote:
> On Mar 12, 4:33 pm, "planetthoughtful" <planetthought...@gmail.com>
> 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

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

KDr2

3/13/2007 1:43:00 AM

0

"planetthoughtful" <planetthoughtful@gmail.com> writes:

> On Mar 13, 10:33 am, "kreiggers" <luckybo...@gmail.com> wrote:
>> On Mar 12, 4:33 pm, "planetthoughtful" <planetthought...@gmail.com>
>> 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
>
> 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.c...

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

------yours Killy Draw

Alpha Chen

3/13/2007 3:34:00 AM

0

On Mar 12, 6:43 pm, KDr2 <K...@163.com> wrote:
> "planetthoughtful" <planetthought...@gmail.com> writes:
> > On Mar 13, 10:33 am, "kreiggers" <luckybo...@gmail.com> wrote:
> >> On Mar 12, 4:33 pm, "planetthoughtful" <planetthought...@gmail.com>
> >> 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/act...

Documentation here:
http://ar.rubyon...

--Alpha Chen

M Wells

3/13/2007 4:52:00 AM

0

On Mar 13, 11:43 am, KDr2 <K...@163.com> wrote:

> > - Where do I get it from, if I can?
>
> there are many sites...for eg:http://rubyforge.vm.bytemark.c...
>
> > - 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

Alpha Chen

3/13/2007 5:26:00 AM

0

On Mar 12, 6:43 pm, KDr2 <K...@163.com> wrote:
> "planetthoughtful" <planetthought...@gmail.com> writes:
> > On Mar 13, 10:33 am, "kreiggers" <luckybo...@gmail.com> wrote:
> >> On Mar 12, 4:33 pm, "planetthoughtful" <planetthought...@gmail.com>
> >> 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/act...

Documentation here:
http://ar.rubyon...

--Alpha Chen