Cannot connect to Digital Ocean Managed Database from Rails Application

October 28, 2019 116 views
DigitalOcean Managed MySQL Database

Hello,
I’m trying to connect to one of our managed databases from the rails application with no luck after trying almost every option out there.

I can successfully connect using the flag string:
mysql -u doadmin -pPASSWORD -h db-XXXXXXXX-prod-do-user-xxxxx-0.db.ondigitalocean.com -P 25060 -D defaultdb

I have tried both doadmin user as well as other users or datbases.
I have tried connecting via the database.yml file with either db url or db details.
I have also tried with and without SSL in my database.yml file.

All options give me the same error:

01 rake aborted!
01 Mysql2::Error::ConnectionError: SSL connection error: unknown error number
01 /home/ordering/public_html/reactive_ordering/production/shared/bundle/ruby/2.5.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `connect'
01 /home/ordering/public_html/reactive_ordering/production/shared/bundle/ruby/2.5.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `initialize'

Here is an example of my database.yml file

default: &default
  adapter: mysql2
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 20 } %>
  timeout: 1000
  encoding: utf8
  sslmode: require
  sslca: <%= Rails.root.join("config/MY-DB.crt") %> 

production:
  <<: *default
  # With connection string
  # url: <%= ENV["DATABASE_URL"] %>

  database: <%= ENV["DATABASE_NAME"] %>
  username: <%= ENV["DATABASE_USERNAME"] %>
  password: <%= ENV["DATABASE_PASSWORD"] %>
  host: <%= ENV["DATABASE_HOST"] %>
  port: 25060

Any help would be much appreciated.
Thank you

1 Answer

Hi! I am having exactly the same issue. I’ve spent a few hours already and I haven’t managed to use DO MySQL yet. Have you found a solution in the meantime? Thanks!

  • Unfortunately not. The strange thing is that I can connect from my development environment but still not possible from the production server.

    • Are you using any firewall?
  • Coming back on this again. I have created an identical droplet taken from a snapshot of the droplet I couldn’t connect and… guess what. I can now connect. However, I will keep digging.

Have another answer? Share your knowledge.