Question

I'm trying to create a new Rails 4.1 project with mysql2 0.3.15 and get the following Error and stack trace. When I force mysql2 0.3.14 there are no errors.

$ rake db:migrate
rake aborted!
TypeError: can't convert nil into String
/usr/local/Cellar/Gems/1.9/gems/mysql2-0.3.15/lib/mysql2/client.rb:67:in `connect'
/usr/local/Cellar/Gems/1.9/gems/mysql2-0.3.15/lib/mysql2/client.rb:67:in `initialize'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/connection_handling.rb:87:in `connection'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/migration.rb:910:in `initialize'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/migration.rb:807:in `new'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/migration.rb:807:in `up'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/migration.rb:785:in `migrate'
/usr/local/Cellar/Gems/1.9/gems/activerecord-4.1.0/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'

This is my database.yml file

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password: "asdf"
  timeout: 5000

development:
  <<: *default
  database: dev
  socket: /tmp/mysql.sock 

production:
  <<: *default
  database: prod
  socket: /var/lib/mysql/mysql.sock

My MySQL client library is 5.6.16 on OSX 10.9.2

UPDATE If I specify password, host, and port in my database.yml file this error goes away. Are these now required for some reason?

Was it helpful?

Solution

I turns out I had hardcoded my GEM_PATH and GEM_HOME rather than letting the gems install in the appropriate rbenv folder. Since I had both ruby 1.9 and 2.1.1 installed, when I installed the new mysql2 gem, the C extensions were compiled against 2.1.1 and caused the above type errors when I tried to connect to the DB. Removing GEM_PATH and GEM_HOME and reinstalling my gems under the .rbenv folder fixed the issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top