RSpec Test - Mysql2::Error::ConnectionError - mysql

Looks like my mysql2 gem is having difficulty connecting to a database. I can connect to mysql database easily using other mysql client tools. I checked the database connection string that is used for RSpec and it is correct. I get following error when I run a_spec.rb spec file.
Failure/Error: #db_client = DBClient.new
Mysql2::Error::ConnectionError:
SSL connection error: error:00000001:lib(0):func(0):reason(1)
# ./vendor/cache/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `connect'
# ./vendor/cache/ruby/2.3.0/gems/mysql2-0.5.2/lib/mysql2/client.rb:90:in `initialize'
# ./helpers/db_client.rb:9:in `new'
# ./helpers/db_client.rb:9:in `initialize'
# ./v1/agent_summary_data_spec.rb:9:in `new'
# ./v1/agent_summary_data_spec.rb:9:in `block (3 levels) in <top (required)>'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `load'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:28:in `run'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli.rb:424:in `exec'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli.rb:27:in `dispatch'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/cli.rb:18:in `start'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/exe/bundle:30:in `block in <top (required)>'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
# /Users/.rvm/gems/ruby-2.3.4/gems/bundler-1.16.2/exe/bundle:22:in `<top (required)>'
I am running following version of mysql in my machine
$ mysql --version
mysql Ver 8.0.12 for osx10.12 on x86_64 (Homebrew)
I am using following gem
$ gem which mysql2
/Users/.rvm/gems/ruby-2.3.4/gems/mysql2-0.5.2/lib/mysql2.rb
Any idea what might be going on? Wondering if anybody has faced similar problem.
Thanks!

In the end, I am able to resolve the above SSL issue. All I did was uninstalled and re-installed mysql2 gem using following commands. It did the magic.
bundle exec gem uninstall mysql2
bundle install

Related

Setting up gemfile for Jekyll - unclear what is wrong

I'm trying to setup a gh-pages site with Jekyll.
When running jekyll server I run into the following error message:
10: from /Users/a56z/.rbenv/versions/2.6.3/bin/jekyll:23:in `<main>'
9: from /Users/a56z/.rbenv/versions/2.6.3/bin/jekyll:23:in `load'
8: from /Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/exe/jekyll:11:in `<top (required)>'
7: from /Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/plugin_manager.rb:52:in `require_from_bundler'
6: from /Users/a56z/.gem/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler.rb:107:in `setup'
5: from /Users/a56z/.gem/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:26:in `setup'
4: from /Users/a56z/.gem/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:26:in `map'
3: from /Users/a56z/.gem/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/spec_set.rb:148:in `each'
2: from /Users/a56z/.gem/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/spec_set.rb:148:in `each'
1: from /Users/a56z/.gem/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:31:in `block in setup'
/Users/a56z/.gem/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/runtime.rb:319:in `check_for_activated_spec!': You have already activated i18n 1.6.0, but your Gemfile requires i18n 0.9.5. Prepending `bundle exec` to your command may solve this. (Gem::LoadError) ```
My Gemfile looks as follows:
# Hello! This is where you manage which Jekyll version is used to run.
# When you want to use a different version, change it below, save the
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
#
# bundle exec jekyll serve
gem 'github-pages'
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
source 'https://rubygems.org'
gem 'jekyll', '3.8.6'
group :jekyll_plugins do
gem 'jekyll-feed'
gem 'jekyll-seo-tag'
end```
Please advise what I'm missing, I've been searching the web but couldn't find anything to make this work.
Also running bundle exec jekyll server doesn't work
I have also simplified the gemfile to this:
gem "jekyll"
gem "minima"
group :jekyll_plugins do
gem "jekyll-feed"
end
but even like so I get this error:
Configuration file: /Users/a56z/code/a56z/blog/my_pytter_blog/_config.yml
Source: /Users/a56z/code/a56z/blog/my_pytter_blog
Destination: /Users/a56z/code/a56z/blog/my_pytter_blog/_site
Incremental build: disabled. Enable with --incremental
Generating...
Jekyll Feed: Generating feed for posts
done in 0.229 seconds.
Auto-regeneration: enabled for '/Users/a56z/code/a56z/blog/my_pytter_blog'
bundler: failed to load command: jekyll (/Users/a56z/.rbenv/versions/2.6.3/bin/jekyll)
Errno::EADDRINUSE: Address already in use - bind(2) for 127.0.0.1:4000
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/socket.rb:201:in `bind'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/socket.rb:201:in `listen'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/socket.rb:764:in `block in tcp_server_sockets'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/socket.rb:227:in `each'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/socket.rb:227:in `foreach'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/socket.rb:762:in `tcp_server_sockets'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/webrick/utils.rb:65:in `create_listeners'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/webrick/server.rb:127:in `listen'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/webrick/server.rb:108:in `initialize'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/2.6.0/webrick/httpserver.rb:47:in `initialize'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/commands/serve.rb:215:in `new'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/commands/serve.rb:215:in `start_up_webrick'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/commands/serve.rb:102:in `process'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `block in process_with_graceful_fail'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `each'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `process_with_graceful_fail'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/commands/serve.rb:86:in `block (2 levels) in init_with_program'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
/Users/a56z/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/exe/jekyll:15:in `<top (required)>'
/Users/a56z/.rbenv/versions/2.6.3/bin/jekyll:23:in `load'
/Users/a56z/.rbenv/versions/2.6.3/bin/jekyll:23:in `<top (required)>'

Heroku rake db:structure:load with cleardb can't find 'mysql'

I am trying to install an instance of Sharetribe on a heroku dyno. I am at the point where I am trying to create the database. I first tried rake db:migrate and it worked for most of the migrations but failed on one of them.
I was advised to use rake db:structure:load, so I tried that and I am getting an error from Heroku saying that mysql needs to be added to the PATH variable. Why is this, and how can I fix it? I'm not sure why it happens on db:schema:load and db:structure:load but not on db:migrate.
The complete stack trace with the error message is:
rake aborted!
failed to execute:
mysqlPlease check the output above for any errors and make sure that `mysql` is installed in your PATH and has proper permissions.
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/mysql_database_tasks.rb:148:in `run_cmd'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/mysql_database_tasks.rb:72:in `structure_load'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:189:in `structure_load'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:222:in `load_schema_for'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:236:in `block in load_schema_current'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:276:in `block in each_current_configuration'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:275:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:275:in `each_current_configuration'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/tasks/database_tasks.rb:235:in `load_schema_current'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/railties/databases.rake:293:in `block (3 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:332:in `exec'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:20:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:11:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/exe/bundle:34:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/exe/bundle:26:in `<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Tasks: TOP => db:structure:load
(See full trace by running task with --trace)
Thanks!
If you need to run heroku run bundle exec rake db:structure:load than you need to install mysql client.
To install additional packages you need to add Buildpacks (official or community based).
For mysql I successfully used https://github.com/din-co/heroku-buildpack-mysql
heroku buildpacks:add --index 1 https://github.com/din-co/heroku-buildpack-mysql
git commit --amend --allow-empty --no-edit
git push heroku -f
Heroku doesn't support mysql, you need to use pg gem in your gemfile in production block.
Please read Getting Started with Rails 5.x on Heroku

Incorrect MySQL client library version! This gem was compiled for 5.5.37 but the client library is 5.6.25 [duplicate]

This question already has answers here:
mysql2 gem compiled for wrong mysql client library
(8 answers)
Closed 6 years ago.
I upgraded my Ubuntu from 2014.04 to 2015.04 and now bundle exec rake db:migrate returns an error:
$ bundle exec rake db:migrate --trace
rake aborted!
Incorrect MySQL client library version! This gem was compiled for 5.5.37 but the client library is 5.6.25.
/home/nico/.rvm/gems/ruby-1.9.3-p362/gems/mysql2-0.2.11/lib/mysql2.rb:9:in `require'
/home/nico/.rvm/gems/ruby-1.9.3-p362/gems/mysql2-0.2.11/lib/mysql2.rb:9:in `<top (required)>'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
/home/nico/myapp/config/application.rb:7:in `<top (required)>'
/home/nico/myapp/Rakefile:4:in `require'
/home/nico/myapp/Rakefile:4:in `<top (required)>'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/rake_module.rb:25:in `load_rakefile'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:583:in `raw_load_rakefile'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:89:in `block in load_rakefile'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:88:in `load_rakefile'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:72:in `block in run'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/bin/rake:19:in `load'
/home/nico/.rvm/gems/ruby-1.9.3-p362#global/bin/rake:19:in `<main>'
/home/nico/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `eval'
/home/nico/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `<main>'
How to solve this problem?
I would rather avoid changing server-side versions.
The answers at I can't run "bundle update" because of "mysql2" gem do not solve the problem.
Local versions:
gem 2.4.8
Rails 3.0.19
mysql Ver 14.14 Distrib 5.6.25
Running these commands solved the problem:
gem uninstall mysql2
bundle install
I ran into the same problem and the accepted answer didn't work for me, most likely because I used capistrano, which installs all gems into a per-app shared directory.
bundle show mysql2
(run in your app's folder) will show you where mysql is installed. Then delete that as well as the the specification.
rm -rf /path/to/application/shared/bundle/ruby/<version>/gems/mysql2-<version>
rm /path/to/application/shared/bundle/ruby/<version>/specifications/mysql2-<version>.gemspec
should do the trick. Alternatively just delete the complete bundle/* and reinstall everything.

Can't get WAMP MySQL to work with Ruby on Rails

I am trying to use my WAMP MySQL for a Ruby on Rails installation on my Windows 7 system. I am getting errors (see below) when I try to start the rails WEBrick server.
I've installed the complete Ruby on Rails environment successfully, including the mysql2 gem. When installing the mysql2 gem, I referenced the location of the lib and includes folders of the WAMP mysql and it successfully installed:
C:\wamp\www\simple_cms>gem install mysql2 --no-document -- '--with-mysql-lib="C:\wamp\bin\mysql\mysql5.5.24\lib\" --with-mysql-include="C:\wamp\bin\mysql\mysql5.5.24\include\"
======================================================================================================
\ You've installed the binary version of mysql2.
It was built using MySQL Connector/C version 6.1.5.
It's recommended to use the exact same version to avoid potential issues.
At the time of building this gem, the necessary DLL files were retrieved from:
http://cdn.mysql.com/Downloads/Connector-C/mysql-connector-c-6.1.5-winx64.zip
\ This gem *includes* vendor/libmysql.dll with redistribution notice in vendor/README.
======================================================================================================
Successfully installed mysql2-0.3.18-x64-mingw32
1 gem installed
I copied the libmysql.dll from "C:\wamp\bin\mysql\mysql5.5.24\lib\libmysql.dll" to "C:\Ruby22-x64\bin\libmysql.dll".
I get the following error when I try to start WEBrick
C:\wamp\www\simple_cms>rails server
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2/mysql2.rb:2:in `require': cannot load such file -- mysql2/2.2/mysql2 (LoadError)
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2/mysql2.rb:2:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2.rb:31:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2-0.3.18-x64-mingw32/lib/mysql2.rb:31:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:76:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:72:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:72:in `block in require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:61:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler/runtime.rb:61:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.4/lib/bundler.rb:134:in `require'
from C:/wamp/www/simple_cms/config/application.rb:7:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:78:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:78:in `block in server'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in `tap'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:75:in `server'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.2/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I have also tried using the libmysql.dll included with the mysql2 gem located at "C:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\mysql2-0.3.18-x64-mingw32\vendor\libmysql.dll" and copying that to "C:\Ruby22-x64\bin\libmysql.dll". That also gave the above errors.
I can access mysql from the command line:
C:\wamp\www\simple_cms>mysql --version
mysql Ver 14.14 Distrib 5.5.24, for Win64 (x86)
I'm not sure what I am doing wrong here. Any help would be appreciated.

Rails application unable to connect to mysql, Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2) (Mysql2::Error)

I'm currently stuck on what is (I hope a newby) problem with a rails project (this is my first rails project and so I apologise if I miss anything crucial). I've been at this for a couple of hours and can't seem to find any solutions. I have tried the solutions to the following threads with no avail.
connect to local MySQL server through socket
Can't connect to local MySQL server through socket
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Can't connect to local MySQL server through socket '/tmp/mysql.sock'
The list goes on, anyway some of the threads are similar to my situation others are just clutching at straws. Let me give you a quick overview of my situation.
The project has been developed on a mac
I have recently set up a test server as a means of learning the deployment process
The server is running Ubuntu Server 12.04
I managed to follow some tutorials to set it up including the Capistrano deployment tutorial up to the point of:
$ rake RAILS_ENV=production db:schema:load
which was where I first encountered the Can't connect to local MySQL server error.
if I run it with --trace I get the following output:
** Invoke db:schema:load (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:277:in `new_connection'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:287:in `checkout_new_connection'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:235:in `block (2 levels) in checkout'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `loop'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `block in checkout'
/usr/share/ruby-rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:308:in `clear_cache!'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/railtie.rb:91:in `block (2 levels) in <class:Railtie>'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:418:in `_run__427268845__prepare__407057367__callbacks'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/actionpack-3.2.2/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/actionpack-3.2.2/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `instance_exec'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `run'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `each'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `run_initializers'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/application.rb:136:in `initialize!'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
/var/www/little_oven_deploy/releases/20120705162026/config/environment.rb:5:in `<top (required)>'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/application.rb:103:in `require_environment!'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/share/ruby-rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/usr/share/ruby-rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/bin/rake:19:in `load'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#global/bin/rake:19:in `<main>'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/bin/ruby_noexec_wrapper:14:in `eval'
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:schema:load => environment
my database.yml file is as follows:
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: little_oven_devel
pool: 5
username: devel
password: Development1
socket: /var/run/mysqld/mysql.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: little_oven_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: little_oven_production
pool: 5
username: production
password: Production1
socket: /var/run/mysqld/mysql.sock
Note that I have changed the location of the socket variable to correspond with what I believe is the .sock file on ubuntu as this differs from a standard install on mac OSX.
finally, I also get the same error when running
rails c
with the following output:
/usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect': Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2) (Mysql2::Error)
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:277:in `new_connection'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:287:in `checkout_new_connection'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:235:in `block (2 levels) in checkout'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `loop'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `block in checkout'
from /usr/share/ruby-rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:308:in `clear_cache!'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activerecord-3.2.2/lib/active_record/railtie.rb:91:in `block (2 levels) in <class:Railtie>'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:418:in `_run__485859349__prepare__1069885904__callbacks'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/actionpack-3.2.2/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/actionpack-3.2.2/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `run'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `each'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/application.rb:136:in `initialize!'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /var/www/little_oven_deploy/releases/20120705162026/config/environment.rb:5:in `<top (required)>'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/application.rb:103:in `require_environment!'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/railties-3.2.2/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I would like to point out that the location /usr/share/ruby-rvm/gems/ruby-1.9.2-p318#rails_3_2/gems/mysql2-0.3.11/lib/mysql2/client.rb is valid. Also, mysql is running and I can access it with:
mysql -u production -p
You can alternatively remove the socket specification from the production environment in database.yml
production:
# socket: /var/run/mysqld/mysql.sock
I understand performance is reduced slightly, but it got me through a similar problem.
/tmp/mysqld.sock is the location of the socket for OSX.
On linux Mint/Ubuntu, it should be at /var/run/mysqld/mysql.sock.
If it's not, then the location should be referenced in one of the MySQL config files, named my.cnf. The location and load order of these files will print out if you enter
mysql --help
into a terminal. If you can't find the my.cnf file at the specified path, it doesn't exist, so ignore it, and look to the next one in the load order.
^ That is the simple, surefire way to verify your socks configuration.
Josh Lewis's answer should be valid, as my Rails 4.0.3 install defaults to omitting the socket line - so I'm assuming it's predefined or auto-configured by the installation, and it's not something you should have to worry about.
Not to revive an old question, but it comes up as a top listing on Google search.
Some random ideas:
Who is the owner of /var/run/mysqld/mysql.sock? I know it's in a first link you mentioned, but maybe you missed it. Is it accessible for user from whom you run commands?
Maybe default MySQL port (3306) is blocked? I suppose it may prevent Rails, even when you're running things locally since in Unix design ports are everywhere. If you're running on Amazon, notice that they keep all ports closed by default (as well as dropping all PING requests by default, but that's another issue) and you may have to click through options in their dashboard
try to add host: 127.0.0.1 and port: 3306 to your production config settings
try to remove pool and reconnect options and see what happens (that's a totally wild guess)
there are some ideas over there, that in such case you should uninstall mysql-client and mysql-server packages and install them again, but I've not seen a point why is that
$ mysqld
f error "mysql-files" dir
$ sudo mkdir /var/lib/mysql-files
$ sudo chown -R mysql:mysql /var/lib/mysql-files/
$ sudo chmod 700 /var/lib/mysql-files/