[英]Rails S command won't work Error: Mysql Socket
I keep running into this error each time I run the command rails s. 每次运行命令rails时,我都会不断遇到此错误。 I have had issues with installing gems, and running bundle from this directory.
我在安装gems以及从该目录运行bundle时遇到问题。 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.
我得到的最高级错误是告诉我MySQL服务器未连接。 I have looked through a few other StackOverFlow threads and none of them have seem to help me.
我浏览了其他一些StackOverFlow线程,但似乎没有一个对我有帮助。 I have a Linux box, running Ubuntu 14.04.
我有一个运行Ubuntu 14.04的Linux机器。 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. Rails试图连接到MySQL数据库。 Do you have it installed on your Linux server?
您是否在Linux服务器上安装了它? What does your
config/database.yml
look like? 您的
config/database.yml
什么样的?
Check out Digital Ocean's guide on Installing Rails, Apache, and MySQL on Ubuntu . 查看Digital Ocean的有关在Ubuntu上安装Rails,Apache和MySQL的指南。
Got it! 得到它了! I had to Purge Mysql, and then re Install it.
我必须清除Mysql,然后重新安装它。
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. 一旦运行此命令,您将在控制台上升级为几则消息,当控制台询问您是否要立即设置权限时,请运行yes命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.