Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Works remotely but not locally #29

Open
andy-twosticks opened this issue Apr 30, 2017 · 2 comments
Open

Works remotely but not locally #29

andy-twosticks opened this issue Apr 30, 2017 · 2 comments

Comments

@andy-twosticks
Copy link

I can connect to MySQL from a different machine, but when I try to connect on the same one I get:

irb(main):006:0> my = Mysql.connect('localhost', 'mythbackdoor', 'notactuallymypassword')
Errno::ENOENT: No such file or directory - connect(2) for /tmp/mysql.sock
        from /usr/local/lib/ruby/gems/2.4.0/gems/ruby-mysql-2.9.14/lib/mysql/protocol.rb:150:in `initialize'
        from /usr/local/lib/ruby/gems/2.4.0/gems/ruby-mysql-2.9.14/lib/mysql/protocol.rb:150:in `new'
        from /usr/local/lib/ruby/gems/2.4.0/gems/ruby-mysql-2.9.14/lib/mysql/protocol.rb:150:in `block in initialize'
        from /usr/local/lib/ruby/2.4.0/timeout.rb:76:in `timeout'
        from /usr/local/lib/ruby/gems/2.4.0/gems/ruby-mysql-2.9.14/lib/mysql/protocol.rb:147:in `initialize'
        from /usr/local/lib/ruby/gems/2.4.0/gems/ruby-mysql-2.9.14/lib/mysql.rb:115:in `new'
        from /usr/local/lib/ruby/gems/2.4.0/gems/ruby-mysql-2.9.14/lib/mysql.rb:115:in `connect'
        from /usr/local/lib/ruby/gems/2.4.0/gems/ruby-mysql-2.9.14/lib/mysql.rb:50:in `new'
        from (irb):6
        from /usr/local/bin/irb:11:in `<main>'

@datacharmer
Copy link

The issue is possibly due to hardcoded location of the socket file (a server issue, not a problem with the connector.)
A workaround could be using '127.0.0.1' instead of 'localhost'.

@tmtm
Copy link
Owner

tmtm commented May 1, 2017

The path of the socket file is specified by the 6th argument of Mysql.connect ().
example:

Mysql.connect('localhost', 'mythbackdoor', 'notactuallymypassword', nil, nil, '/path/to/socket')

This value can also be given as an environment variable MYSQL_UNIX_PORT:

% export MYSQL_UNIX_PORT=/path/to/socket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants