简体   繁体   English

Rails Mysql ActiveRecord ::连接未建立

[英]Rails Mysql ActiveRecord::ConnectionNotEstablished

I created a new rails application, when i started server an tried to connect it gave this server 我创建了一个新的Rails应用程序,当我启动服务器时尝试连接该服务器

error 错误

activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:53:in `connection'
activerecord (4.0.0) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
activerecord (4.0.0) lib/active_record/query_cache.rb:43:in `rescue in call'
activerecord (4.0.0) lib/active_record/query_cache.rb:32:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__713349442__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
C:/Ruby23/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
C:/Ruby23/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
C:/Ruby23/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

database.yml 数据库

development:
  adapter: mysql2
  encoding: utf8
  database: simple_cms_development
  pool: 5
  username: root
  password: root
  host: 127.0.0.1

Mysql is running and the password is correct. Mysql正在运行,密码正确。 I tried connecting from command line 我尝试从命令行连接

G:\simple_cms>mysql -uroot -proot simple_cms_development
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Can someone tell me what might be the possible cause for that error 有人可以告诉我该错误的可能原因是什么

Have a look at your /etc/mysql/my.cnf and check for the binding address of the mysql deamon. 查看您的/etc/mysql/my.cnf并检查mysql守护进程的绑定地址。 It probably doesnt bind to any ip. 它可能不绑定到任何IP。 Then it will use unix sockets which are by the way faster then ip connections,... 然后它将使用unix套接字,顺便说一下,该套接字要比ip连接快,...

Option name for the bind address is bind-address if theres no match it wont bind to any address. 如果没有匹配项,则绑定地址的选项名称为bind-address,它将不会绑定到任何地址。 Also have a look for socket which specifies the path to the unix socket. 还可以查找套接字,该套接字指定到UNIX套接字的路径。 You can use the socket like this in your database.yml 您可以在数据库中使用这样的套接字。

development:
  adapter: mysql2
  encoding: utf8
  database: simple_cms_development
  username: root
  password: root
  host: 127.0.0.1
  pool: 5
  socket: /path/to/the/socket/mysql.sock

That should do it for you, 那应该为你做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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