我猜测的是,当我删除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”连接到此数据库 我查看了themysql2代码,它没有采用协议参数。它只使用套接字。
型号: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'
答案 0 :(得分:25)
在mysql中,localhost是“魔术”,它意味着使用套接字。请尝试使用127.0.0.1。