title: Ruby on Rails: How to work with RDS MySQL instance locally
body: <h2>Environment</h2>
  
  <ul>
  <li><code>Rails version: 6.0.0.rc2</code></li>
  <li><code>Ruby version: ruby 2.6.3p62 (2019-04-16 revision 67580)</code></li>
  <li><code>RDS MySql:  Ver 8.0.15</code></li>
  </ul>
  
  <h2>Problem</h2>
  
  <p>I am trying to connect my RDS MySQL8 instance to my local Ruby on Rails application for testing purposes. My app is working fine with a local version of <code>MySQL8.0.12</code> with the <code>mysql2</code> gem.</p>
  
  <p>When I use the RDS DB's details and I run <code>bin/rake db:[anything] VERBOSE=true</code> in the command line, it just hangs without giving ANY information on why it isn't working. Output below.</p>
  
  <p>This is purely to test the db I want to use for a staging environment.</p>
  
  <ul>
  <li>I've connected to the RDS DB from the command line and DBeaver from my local machine, and I've been able to create new tables, so security groups should be ok. </li>
  <li>I've used the db connection test script below to ensure that <code>ActiveRecord::Base.connected</code> is true</li>
  <li>Connected, initiated, migrated and seeded a local mysql db just in case. </li>
  </ul>
  
  <p><code>database.yml</code></p>
  
  <pre class="lang-rb prettyprint-override"><code>#
  default: &amp;default
    adapter: mysql2
    encoding: utf8mb4
    pool: &lt;%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %&gt;
    host: [aws_rds_host_url]
    username:  &lt;%= ENV.fetch("DB_USERNAME") %&gt;
    password: &lt;%= ENV.fetch("DB_PASSWORD") %&gt;
    database: db_name
  </code></pre>
  
  <p>test script found somewhere on stackoverflow (returns "CONNECTED!")</p>
  
  <pre class="lang-rb prettyprint-override"><code>require './config/environment.rb' # Assuming the script is located in the root of the rails app
  begin
    ActiveRecord::Base.establish_connection # Establishes connection
    ActiveRecord::Base.connection # Calls connection object
    puts "CONNECTED!" if ActiveRecord::Base.connected?
    puts "NOT CONNECTED!" unless ActiveRecord::Base.connected?
  rescue StandardError =&gt; e
    puts e
    puts "rescue:: NOT CONNECTED!"
  end
  </code></pre>
  
  <p>Running <code>bin/rake db:create VERBOSE=true</code> ||  <code>bin/rake db:migrate VERBOSE=true</code> (or anything <code>rake db:</code>) keeps hanging, tried for more than an hour. It does not make any changes to the DB. Stopped with cmd+C it just returns:</p>
  
  <pre class="lang-rb prettyprint-override"><code>bin/rake db:create VERBOSE=true                                                                                                                                                        
  ^CTraceback (most recent call last):
      14: from bin/rake:3:in `&lt;main&gt;'
      13: from bin/rake:3:in `load'
      12: from [home]/[project dir]/bin/spring:16:in `&lt;top (required)&gt;'
      11: from [home]/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
      10: from [home]/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
       9: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `&lt;top (required)&gt;'
       8: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
       7: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/bin/spring:49:in `&lt;top (required)&gt;'
       6: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
       5: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
       4: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:35:in `call'
       3: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:42:in `warm_run'
       2: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:62:in `run'
       1: from [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:117:in `verify_server_version'
  [home]/[project dir]/vendor/bundle/ruby/2.6.0/gems/spring-2.1.0/lib/spring/client/run.rb:117:in `gets': Interrupt
  
  </code></pre>