내가 추측하는 바는 소켓 매개 변수를 제거하면 mysql2가 TCP 연결 프로토콜을 기본값으로 사용하지 않는다는 것이다. 너희들도 동의하니? 모든 GEM 제안?rails3 mysql2 GEM이 TCP를하지 않는 것 같아 소켓
mysql 명령 줄을 통해 연결할 수 있습니다. 그래서 모든 것이 mysql 관점에서 구성됩니다.
이 줄은 잘 연결 : "MySQL의 -P 3406 -u 사용자 ID -p --protocol = -h localhost를 TCP"비밀번호 입력 :
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
레일 콘솔
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/[email protected]/gems/mysql2-0.2.7/lib/mysql2/client.rb:42:in `connect'
from /Users/michael.pechner/.rvm/gems/[email protected]/gems/mysql2-0.2.7/lib/mysql2/client.rb:42:in `initialize'
from /Users/michael.pechner/.rvm/gems/[email protected]/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:14:in `new'
from /Users/michael.pechner/.rvm/gems/[email protected]/gems/mysql2-0.2.7/lib/active_record/connection_adapters/mysql2_adapter.rb:14:in `mysql2_connection'
from /Users/michael.pechner/.rvm/gems/[email protected]/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `new_connection'
우수. 이것은 효과가 있었다. 이제는 테이블 이름이 복수형이 아니라는 것을 모델에 알려줘야한다는 것이 문제입니다. – mpechner
@mpecher AR 클래스에서 set_table_name = "notpluralname"을 사용하십시오. – Wes