简体   繁体   中英

Rails S command won't work Error: Mysql Socket

I keep running into this error each time I run the command rails s. I have had issues with installing gems, and running bundle from this directory. All I want to do is run my server on the designated port. I think I might not have the right credentials to run the server locally. The top level error I got is telling me that the MySQL server is not connecting. I have looked through a few other StackOverFlow threads and none of them have seem to help me. I have a Linux box, running Ubuntu 14.04. Please Help.


>  yonas@yonas:~/code/freelance/buh/impact$ rails s
    >         => Booting Thin
    >         => Rails 3.2.13 application starting in development on http://0.0.0.0:3000
    >         => Call with -d to detach
    >         => Ctrl-C to shutdown server
    >         Exiting
    >         /var/lib/gems/1.9.1/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in
    > `connect': Can't connect to local MySQL server through socket
    > '/tmp/mysql.sock' (2) (Mysql2::Error)
    >                 from /var/lib/gems/1.9.1/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in
    > `initialize'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in
    > `new'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in
    > `mysql2_connection'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in
    > `new_connection'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in
    > `checkout_new_connection'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in
    > `block (2 levels) in checkout'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in
    > `loop'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in
    > `block in checkout'
    >                 from /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in
    > `checkout'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in
    > `block in connection'
    >                 from /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in
    > `connection'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in
    > `retrieve_connection'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in
    > `retrieve_connection'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in
    > `connection'
    >                 from /var/lib/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/railtie.rb:88:in
    > `block in <class:Railtie>'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in
    > `instance_exec'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in
    > `run'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in
    > `block in run_initializers'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in
    > `each'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in
    > `run_initializers'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in
    > `initialize!'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in
    > `method_missing'
    >                 from /home/yonas/code/freelance/HUB/impact-hub-seattle/config/environment.rb:5:in
    > `<top (required)>'
    >                 from /var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in
    > `require'
    >                 from /var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in
    > `block in require'
    >                 from /var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in
    > `load_dependency'
    >                 from /var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in
    > `require'
    >                 from /home/yonas/code/freelance/HUB/impact-hub-seattle/config.ru:3:in
    > `block in <main>'
    >                 from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in
    > `instance_eval'
    >                 from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in
    > `initialize'
    >                 from /home/yonas/code/freelance/HUB/impact-hub-seattle/config.ru:in `new'
    >                 from /home/yonas/code/freelance/HUB/impact-hub-seattle/config.ru:in
    > `<main>'
    >                 from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
    >                 from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in
    > `parse_file'
    >                 from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in
    > `app'
    >                 from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:304:in
    > `wrapped_app'
    >                 from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in
    > `start'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:55:in
    > `block in <top (required)>'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in
    > `tap'
    >                 from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in
    > `<top (required)>'
    >                 from script/rails:6:in `require'
    >                 from script/rails:6:in `<main>'

    #
# 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: <%= ENV['HUB_DEV_DB'] %>
  pool: 5
  username: <%= ENV['HUB_DEV_USER'] %>
  password: <%= ENV['HUB_DEV_PASS'] %>
  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: mysql2
  encoding: utf8
  reconnect: false
  database: <%= ENV['HUB_TEST_DB'] %>
  pool: 5
  username: <%= ENV['HUB_TEST_USER'] %>
  password: <%= ENV['HUB_TEST_PASS'] %>
  socket: /tmp/mysql.sock

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: hub_production
  pool: 5
  username: root
  password: hub123
  socket: /var/run/mysqld/mysqld.sock

development:
  adapter: mysql2
  username: root
  password: the_truth34
  socket: /tmp/sockets/mysql.sock

Rails is trying to connect to a MySQL database. Do you have it installed on your Linux server? What does your config/database.yml look like?

Check out Digital Ocean's guide on Installing Rails, Apache, and MySQL on Ubuntu .

Got it! I had to Purge Mysql, and then re Install it.

sudo apt-get remove --purge mysql-server mysql-client mysql-common

sudo apt-get autoremove

sudo apt-get autoclean

Then I used the doc below to re install it. (Link below)

Follow console steps very closely

When running this command:

sudo mysql_secure_installation

Once you run this command you will be promoted to a few messages on your console, run the yes command when the console asks you if you want to set permissions now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM