title: rake db:create error with mysql2 gem (Couldn't create database for {"adapter"=>"mysql2")
body: <p>I'm trying to get rails 4 up and running together with ruby 2.0 on my debian 7 box and I'm having issues connecting to a mysql database with mysql2 gem.</p>
  
  <p>I have used the commands below to set up the everything around:</p>
  
  <pre>
  \curl -L https://get.rvm.io | bash -s stable
  rvm install ruby   
  rvm use ruby --default
  rvm rubygems current 
  gem install rails --no-ri --no-rdoc
  </pre>
  
  <p>When I try to run rake db:create and I'm getting the follow error:</p>
  
  <pre>
  <code>
  no implicit conversion of Fixnum into String
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `connect'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `initialize'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
  /home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
  /home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:72:in `create'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:86:in `block in create_current'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:182:in `block in each_current_configuration'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:181:in `each'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:181:in `each_current_configuration'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:85:in `create_current'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:20:in `block (2 levels) in '
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
  /home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/bin/rake:33:in `'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `load'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `'
  Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"myapp_development", "pool"=>5, "username"=>"dev", "password"=>password, "socket"=>"/var/run/mysqld/mysqld.sock"}
  no implicit conversion of Fixnum into String
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `connect'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `initialize'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
  /home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
  /home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:72:in `create'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:86:in `block in create_current'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:182:in `block in each_current_configuration'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:181:in `each'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:181:in `each_current_configuration'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:85:in `create_current'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:20:in `block (2 levels) in '
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
  /home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/bin/rake:33:in `'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `load'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
  /home/mayrun/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `'
  Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"myapp_test", "pool"=>5, "username"=>"dev", "password"=>password, "socket"=>"/var/run/mysqld/mysqld.sock"}
  </pre>
  
  <p></code></p>
  
  <p>My inspections after having a deep look:</p>
  
  <ul>
  <li>mysql is up and running</li>
  <li>mysql username and password are correct.  </li>
  <li>mysql is listening to localhost and 127.0.0.1  </li>
  <li>/var/run/mysqld/mysqld.sock file exists  </li>
  <li>I looked at the mysql logs and it seem slike  mysql2 is not even attempting to connect.  </li>
  <li>when replacing mysql2 gem with the older, slower mysql gem, the problem goes away.  </li>
  </ul>
  
  <p>My mysql version:</p>
  
  <pre><code>$ mysql --version    
  mysql  Ver 14.14 Distrib 5.5.31, for debian-linux-gnu (x86_64) using readline 6.2    
  </code></pre>
  
  <p>This is my database/config.yml file:</p>
  
  <pre><code>
  development:
    adapter: mysql2
    encoding: utf8
    database: myapp_development
    pool: 5
    username: dev
    password: password
    host: localhost
    socket: /var/run/mysqld/mysqld.sock
  
  test:
    adapter: mysql2
    encoding: utf8
    database: myapp_test
    pool: 5
    username: dev
    password: password
    socket: /var/run/mysqld/mysqld.sock
  
  production:
    adapter: mysql2
    encoding: utf8
    database: myapp_production
    pool: 5
    username: dev
    password: password
    socket: /var/run/mysqld/mysqld.sock
  </code></pre>
  
  <p>Local gem list:</p>
  
  <pre>
  *** LOCAL GEMS ***
  
  actionmailer (4.0.0)
  actionpack (4.0.0)
  activemodel (4.0.0)
  activerecord (4.0.0)
  activerecord-deprecated_finders (1.0.3)
  activesupport (4.0.0)
  arel (4.0.1)
  atomic (1.1.14)
  builder (3.1.4)
  bundler (1.3.5)
  bundler-unload (1.0.2)
  coffee-rails (4.0.1)
  coffee-script (2.2.0)
  coffee-script-source (1.6.3)
  erubis (2.7.0)
  execjs (2.0.2)
  executable-hooks (1.2.6)
  hike (1.2.3)
  i18n (0.6.5)
  jbuilder (1.5.2)
  jquery-rails (3.0.4)
  json (1.8.1)
  mail (2.5.4)
  mime-types (1.25)
  minitest (4.7.5)
  multi_json (1.8.2)
  mysql2 (0.3.13)
  polyglot (0.3.3)
  rack (1.5.2)
  rack-test (0.6.2)
  rails (4.0.0)
  railties (4.0.0)
  rake (10.1.0)
  rdoc (3.12.2)
  rubygems-bundler (1.4.1)
  rvm (1.11.3.8)
  sass (3.2.12)
  sass-rails (4.0.1)
  sdoc (0.3.20)
  sprockets (2.10.0)
  sprockets-rails (2.0.1)
  thor (0.18.1)
  thread_safe (0.1.3)
  tilt (1.4.1)
  treetop (1.4.15)
  turbolinks (1.3.0)
  tzinfo (0.3.38)
  uglifier (2.3.0)
  </pre>
  
  <p>Packages installed:</p>
  
  <pre><code>$ sudo dpkg -l | grep mysql
  ii  libdbd-mysql-perl                  4.021-1+b1                    amd64        Perl5 database interface to the MySQL database
  ii  libmysqlclient-dev                 5.5.31+dfsg-0+wheezy1         amd64        MySQL database development files
  ii  libmysqlclient18:amd64             5.5.31+dfsg-0+wheezy1         amd64        MySQL database client library
  ii  mysql-client                       5.5.31+dfsg-0+wheezy1         all          MySQL database client (metapackage depending on the latest version)
  ii  mysql-client-5.5                   5.5.31+dfsg-0+wheezy1         amd64        MySQL database client binaries
  ii  mysql-common                       5.5.31+dfsg-0+wheezy1         all          MySQL database common files, e.g. /etc/mysql/my.cnf
  ii  mysql-server                       5.5.31+dfsg-0+wheezy1         all          MySQL database server (metapackage depending on the latest version)
  ii  mysql-server-5.5                   5.5.31+dfsg-0+wheezy1         amd64        MySQL database server binaries and system database setup
  ii  mysql-server-core-5.5              5.5.31+dfsg-0+wheezy1         amd64        MySQL database server binaries
  ii  php5-mysql                         5.4.4-14+deb7u5               amd64        MySQL module for php5
  </code></pre>