Ruby and MySQL Connection

ruby
docker
mysql

#1

I’m having an issue getting my Ruby application to connect to the MySQL database while running tests in CircleCI.

When specifying host: localhost in my database.yml I get the following error:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Couldn't create database for {"adapter"=>"mysql2", "database"=>"circle_test", "username"=>"root", "host"=>"localhost"}, charset: utf8, collation: utf8_unicode_ci

This is correct, since the database is not in the same container, so I edit my database.yml to change the localhost connection to host: 127.0.0.1. This, however still fails with the following (I truncated the stack trace):

ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
/home/circleci/workingdir/vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.22.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection'
/home/circleci/workingdir/vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.22.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
/home/circleci/workingdir/vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.22.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
/home/circleci/workingdir/vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.22.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:130:in `establish_connection'
/home/circleci/workingdir/vendor/bundle/ruby/2.1.0/gems/activerecord-import-0.3.1/lib/activerecord-import.rb:4:in `establish_connection_with_activerecord_import'

......

I was able to test the connection by installing the mysql client, and the connection itself works just fine:

circleci@b464fb090270:~/workingdir$ mysql -u root -h 127.0.0.1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.5.56 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| circle_test        |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

Anyone have any ideas??


#2

Can you share your config/database.yml?


#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.