Rails S命令不起作用错误:Mysql Socket

时间:2015-06-24 02:52:13

标签: mysql ruby-on-rails ruby

每次运行命令rails s时,我都会遇到此错误。我在安装gems和从这个目录运行bundle时遇到了问题。我想要做的就是在指定端口上运行我的服务器。我想我可能没有正确的凭据来在本地运行服务器。我收到的顶级错误告诉我MySQL服务器没有连接。我查看了一些其他StackOverFlow线程,但它们似乎都没有帮助我。我有一个Linux机器,运行Ubuntu 14.04。请帮忙。

>  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

2 个答案:

答案 0 :(得分:0)

Rails正在尝试连接MySQL数据库。你在Linux服务器上安装了吗?你的config/database.yml看起来像什么?

查看Installing Rails, Apache, and MySQL on Ubuntu上的Digital Ocean指南。

答案 1 :(得分:0)

知道了!我不得不Purge Mysql,然后重新安装它。

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

sudo apt-get autoremove

sudo apt-get autoclean

然后我使用下面的文档重新安装它。 (链接如下)

Follow console steps very closely

运行此命令时:

sudo mysql_secure_installation

运行此命令后,您将在控制台上升级为几条消息,当控制台询问您是否要立即设置权限时,请运行yes命令。