簡體   English   中英

rails3 mysql2 GEM似乎沒有TCP,只有socket

[英]rails3 mysql2 GEM does not seem to do TCP, only socket

我猜測的是,當我刪除socket參數時,mysql2沒有默認為TCP連接協議。 你們同意嗎? 任何創業板建議?

我可以通過mysql命令行連接。 所以,從mysql的角度來看,所有配置都是如此。

這行很好地連接:“mysql -P 3406 -u userid -p --protocol = TCP -h localhost”輸入密碼:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 77402
Server version: 5.0.77-log Source distribution

Copyright (c) 2000, 2010, 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> show databases;
+---------------------+
| Database            |
+---------------------+

database.yml的

svc_development:
    adapter: mysql2
    encoding: utf8
    database: my_db
    username: userid
    password: apasswd
    host: localhost
    port: 3406  

該端口對於此實例是正確的。 我通過SSH隧道“-L 3406:host:3306”連接到這個數據庫我看了一下itysql2代碼,它沒有采用協議參數。 它只使用套接字。

型號:looky_loo.rb

class LookyLoo < ActiveRecord::Base
    self.abstract_class = true
    establish_connection  "svc_development"
end

從Rails控制台

from script/rails:6:in `<main>'ruby-1.9.2-p136 :002 > LookyLoo.all
Mysql2::Error: Access denied for user 'userid'@'localhost' (using password: YES)
    from /Users/michael.pechner/.rvm/gems/ruby-1.9.2-p136@amqp/gems/mysql2-0.2.7/lib/mysql2/client.rb:42:in `connect'
    from /Users/michael.pechner/.rvm/gems/ruby-1.9.2-p136@amqp/gems/mysql2-0.2.7/lib/mysql2/client.rb:42:in `initialize'
    from /Users/michael.pechner/.rvm/gems/ruby-1.9.2-p136@amqp/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:14:in `new'
    from /Users/michael.pechner/.rvm/gems/ruby-1.9.2-p136@amqp/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:14:in `mysql2_connection'
    from /Users/michael.pechner/.rvm/gems/ruby-1.9.2-p136@amqp/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `new_connection'

在mysql中,localhost是“魔術”,它意味着使用套接字。 請嘗試使用127.0.0.1。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM