Ruby and MySQL Connection



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: 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- `resolve_hash_connection'
/home/circleci/workingdir/vendor/bundle/ruby/2.1.0/gems/activerecord- `resolve_string_connection'
/home/circleci/workingdir/vendor/bundle/ruby/2.1.0/gems/activerecord- `spec'
/home/circleci/workingdir/vendor/bundle/ruby/2.1.0/gems/activerecord- `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
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

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??


Can you share your config/database.yml?


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