K
Kyle
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
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