简体   繁体   中英

Can't connect to remote mysql database ruby on rails

I have the following problem:

I'm trying to connect to a mysql database on my remote host. I use the following ruby code

  client  = Mysql2::Client.new(:host => HOST, :username => USER, :password => PASS)

But what I am getting is:

  Mysql2::Error:
  Can't connect to MySQL server on HOST (4)

I can connect to the host from the command line, using

  mysql -u USER -p -h HOST

I can also connect with the command above (client = Mysql2::...) to the DB, that runs in VirtualBox.

What am I missing? Thanks!

In this statement:

I can also connect with the command above (client = Mysql2::...) to the DB, that runs in VirtualBox.

Are you saying you can connect in Ruby on the VirtualBox machine that is actually running the database? If so, you're looking at firewall issues, or MySQL isn't configured to allow remote connections .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM