2

Im new with rails and Im trying to execute rake db:schema:dump, but Im having this problem.

rake db:schema:dump --trace
** Invoke db:schema:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:schema:dump
rake aborted!
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
/var/lib/gems/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect'
/var/lib/gems/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection
'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_co
nnection'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checko
ut_new_connection'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block 
(2 levels) in checkout'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block 
in checkout'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checko
ut'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block 
in connection'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connec
tion'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrie
ve_connection'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:i
n `retrieve_connection'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:i
n `connection'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:379:in `block (4 levels) in <top (requ
ired)>'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:378:in `open'
/var/lib/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:378:in `block (3 levels) in <top (requ
ired)>'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/var/lib/gems/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Tasks: TOP => db:schema:dump

I already create the database and Im having this problem when I try to connect.

My database.yml is:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
# development:
  # adapter: sqlite3
  # database: db/development.sqlite3
  # pool: 5
  # timeout: 5000

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: simple_cms_develoment  
  pool: 5
  username: simple_cms
  password: secretpassword
  socket: /tmp/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: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

And my gemfile is:

source 'https://rubygems.org'

gem 'rails', '3.2.9'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2'

gem 'activerecord-mysql-adapter'

gem 'bootstrap-sass'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

Can anyone help me?

  • What is in your GemFile? 'pg' or 'sqlite3' or 'mysql'? – Nishant Jan 01 '13 at 07:43
  • gem 'mysql2' gem 'activerecord-mysql-adapter' – Julio Sousa Jan 01 '13 at 07:48
  • What DB are you using? Mysql? – Nishant Jan 01 '13 at 07:50
  • Yes, mysql. It was pre-configurated with sqlite but I change to mysql – Julio Sousa Jan 01 '13 at 07:51
  • I dont know with I did something wrong in this change. – Julio Sousa Jan 01 '13 at 07:51
  • After changing the gem did you run bundle install? Also, are DB details in your environment configuration file correct? – Nishant Jan 01 '13 at 07:53
  • Yes. I did run bundle install, and I have mysql2 and active-records on it. – Julio Sousa Jan 01 '13 at 07:55
  • Yes. I did run bundle install, and I have mysql2 and active-records on it. Yes, eveything in the config is correct. I have doubt about socket: /tmp/mysql.sock. – Julio Sousa Jan 01 '13 at 08:00
  • I change the configuration now I have this line: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) – Julio Sousa Jan 01 '13 at 08:24
  • What is the error code for that error? Try restarting mysql. Also now this is entirely a question w.r.t mysql. so you might want to post a new question for that or look here http://stackoverflow.com/questions/5376427/cant-connect-to-local-mysql-server-through-socket-var-mysql-mysql-sock-38 and http://stackoverflow.com/questions/4788381/getting-cant-connect-through-socket-tmp-mysql-when-installing-mysql-on-m – Nishant Jan 01 '13 at 08:27
  • Ok, I edited my question and put the content of the files here. This is my first question on stackoverflow. Thank you, Nishant – Julio Sousa Jan 01 '13 at 08:31
  • Is mysql really running? Does the file "/tmp/mysql.sock" actually exist? For some mysql installations you need to start it manually or the socket file is in a different place. What OS do you use? – thorsten müller Jan 01 '13 at 08:33
  • Resolved, Nishant. I enter in the file /etc/mysql/my.cnf and i found the line socket = /var/run/mysqld/mysqld.sock and I replace on the config file. Thank you. – Julio Sousa Jan 01 '13 at 08:37
  • I use ubuntu 12. Can anyone reply for me check answered question? – Julio Sousa Jan 01 '13 at 08:37

1 Answers1

2

Assuming you are using ubuntu, you have the wrong path to the socket file
changed to socket: /var/run/mysqld/mysqld.sock

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: simple_cms_develoment  
  pool: 5
  username: simple_cms
  password: secretpassword
  socket: /var/run/mysqld/mysqld.sock
Eugene Rourke
  • 4,934
  • 1
  • 22
  • 24