Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Ruby DBI MySQL: how to specify protocol=tcp

Reply
Thread Tools

Ruby DBI MySQL: how to specify protocol=tcp

 
 
Kyle
Guest
Posts: n/a
 
      04-14-2008
Hello! I'm using a ruby script to synchronize a remote (web) MySQL
database with a local database. I had been remotely accessing the
database through a non-standard port, but I would much rather use an
SSH tunnel for security. I can set up the tunnel to point port 3307
on the local machine to 3306 (MySQL) on the remote host. When using
mysql from the command line, I'm able to connect if I specify --
protocol=tcp. Otherwise, MySQL tries to use a socket, and it fails.

Using Ruby DBI::MySQL, I can't seem to specify --protocol=tcp. I've
put this in both /etc/mysql/my.cnf and ~/.my.cnf so that I no longer
have to explicitly state it from the command line. Still, my script
is unable to connect. Here is the connection setup in my code:

mysql = DBI.connect('dbi:Mysql:database=dbname;port=3307', 'user',
'pass')

Here's the error:

/usr/lib/ruby/1.8/DBD/Mysql/Mysql.rb:115:in `error': Can't connect to
local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
(DBI:atabaseError)
from /usr/lib/ruby/1.8/DBD/Mysql/Mysql.rb:171:in `connect'
from /usr/lib/ruby/1.8/dbi.rb:424:in `connect'
from /usr/lib/ruby/1.8/dbi.rb:215:in `connect'
from slice-inventory-sync.rb:9

(Note: specifying host=localhost does the same and host=remotehost
fails.)

Any ideas on how I can get --protocol=tcp specified in my script?

Thanks!

-Kyle

 
Reply With Quote
 
 
 
 
Roger Pack
Guest
Posts: n/a
 
      04-15-2008

> mysql = DBI.connect('dbi:Mysql:database=dbname;port=3307', 'user',
> 'pass')

yeah try specifying the host as either '127.0.0.1' or 'localhost' -- one
of the two ignores the sock.
You can also take a look at
http://code.google.com/p/ruby-roger-...runk/syncer.rb
for some nice references on how to build a solid version of what you're
building.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Kyle
Guest
Posts: n/a
 
      04-15-2008
Roger,

Thanks for the tips! I had tried specifying host=localhost, but I
hadn't tried host=127.0.0.1. It works! Bizarre...

Thanks for the link, too. It's definitely more robust than what I
have, but I'm happy with my solution for now. If I build another sync
script some time, I'll take some good ideas from that program.

-Kyle

On Apr 15, 12:15 am, Roger Pack <(E-Mail Removed)> wrote:
> > mysql = DBI.connect('dbi:Mysql:database=dbname;port=3307', 'user',
> > 'pass')

>
> yeah try specifying the host as either '127.0.0.1' or 'localhost' -- one
> of the two ignores the sock.
> You can also take a look athttp://code.google.com/p/ruby-roger-useful-functions/source/browse/tr...
> for some nice references on how to build a solid version of what you're
> building.
>
> --
> Posted viahttp://www.ruby-forum.com/.


 
Reply With Quote
 
Roger Pack
Guest
Posts: n/a
 
      04-15-2008
Kyle wrote:
> Roger,
>
> Thanks for the tips! I had tried specifying host=localhost, but I
> hadn't tried host=127.0.0.1. It works! Bizarre...

yeah it's a mysql thing. I have no idea why they did that.

The one I was most happy to discover was how to use compression. That
rocked
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
DBI Mysql storing DBI:binary, trouble with character 26 Jerome Hauss Ruby 0 10-13-2004 03:04 PM
DBI and DBI::Oracle packages configuration ulloa Perl 1 07-22-2004 05:52 PM
DBI problem : How can I load quickly one huge table with DBI ??. Tim Haynes Perl Misc 3 09-13-2003 03:43 AM
Mason, DBI, and DBI::Pg Asby Perl Misc 0 07-24-2003 09:04 PM



Advertisments