2012-01-02 1 views
3

InnoDB를 사용하지 않고 실행중인 MySQL 서버가 있습니다 (성능상의 이유로),이 설정으로 Rails 3 (mysql2 어댑터 사용)을 사용할 수없는 것 같습니다.InnoDB없이 MySQL MyISAM 모드에서 Rails 3을 실행할 수 없습니까?

여기 내 테스트 마이그레이션입니다 :

class CreateTxts < ActiveRecord::Migration 
    def change 
    create_table(:txts, :options => 'ENGINE=MyISAM') do |t| 
     t.timestamps 
    end 
    end 
end 

그리고 여기에 오류 발생 :

>rake db:migrate 
rake aborted! 
Mysql2::Error: Unknown storage engine 'InnoDB': CREATE TABLE `schema_migrations` 
(`version` varchar(255) NOT NULL) ENGINE=InnoDB 

가 해결 here을 설명했지만,이 중 하나 (내가 Mysql2Adapter에 MysqlAdapter을 수정했다 작동하지 않는 것 내 설정과 일치).

죄송합니다. 저는 Rails의 newb입니다. 어떤 도움을 많이 주시면 감사하겠습니다 :

답변

11

내 질문에 대답하려고합니다. 여기에 내가 그와 함께 결국 environment.rb에 대한 패치는 기본 MySQL의 드라이버뿐만 아니라 JRuby를가/JDBC-MySQL의 작동입니다 :

# Load the rails application 
require File.expand_path('../application', __FILE__) 

# Patch Mysql adapter to default to MyISAM instead of InnoDB 
require 'active_record/connection_adapters/mysql_adapter' 
module ActiveRecord 
    module ConnectionAdapters 
    class MysqlAdapter 
     def create_table(table_name, options = {}) #:nodoc: 
     super(table_name, options.reverse_merge(:options => "ENGINE=MyISAM")) 
     end 
    end 
    end 
end 

# Initialize the rails application 
..... 

rake db:migrate 지금 성공하고 TYPE =의 MyISAM과 schema_migrations 포함한 모든 테이블을 생성합니다.

참고 : mysql2 어댑터의 경우 mysql_adapter의 이름을 mysql2_adapter로 변경하고 MysqlAdapter의 이름을 Mysql2Adapter로 바꿉니다.

+1

'Module ActiveRecord module ConnectionAdapters class MysqlAdapter'를'class ActiveRecord :: ConnectionAdapters :: MysqlAdapter'로 대체하면 더 짧아 질 수 있습니다. –

0

schema_migrations 테이블 (레일스는 어떤 마이그레이션이 실행되었는지를 추적하는 데 사용함)을 만들 때 오류가 발생합니다. 인덱스를 가진 version이라는 단일 varchar (255) 열을 사용하여 직접 테이블을 만들 수 있습니다.

create_table 메서드를 덮어 쓰게되면 메서드의 서명을 보존해야합니다. 즉, 생성 된 블록을 무시할 수 있습니다. 나는 엔진의 종류를 지정하지 않고 테이블을 생성

def create_table(name, options={}) 
    super(name, options.merge(...)) {|t| yield t} 
end 
+0

아니요 원래 MysqlAdapter의 create_table에 수율 블록이 없습니다. – rustyx

+0

수퍼 유저의 행동에 대해 혼란스러워합니다. 직접 스키마 마이그레이션 테이블을 만들려고 했습니까? –

1

보십시오이

class CreateTxts < ActiveRecord::Migration 
    def change 
    create_table(:txts) do |t| 
     t.timestamps 
    end 
    end 
end 

처럼 사용하고 MySQL의 CLI에서이

ALTER TABLE txts ENGINE = MYISAM 

희망을 입력하고 같은 것을 시도 할 것 도움이

+0

MySQL 서버에서 InnoDB를 사용할 수 없으므로 도움이되지 않습니다. 작동하지 않습니다. – rustyx

0

@rustyx 멋진 사람! /config/initializers/mysql2adapter_default_engine.rb :

&보다는 /config/environment.rb에서

, 난 예, 이니셜 라이저에 코드를 넣어 : & 여기 이렇게 엔진이 /config/database.yml 구성 내에서 설정할 수 있습니다 내 약간 불통 원숭이 패치입니다.


어느 쪽이 간결에 대한 자세한 명확성을 위해

require 'active_record/connection_adapters/abstract_mysql_adapter' 

class ActiveRecord::ConnectionAdapters::Mysql2Adapter < ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter 
    def create_table(table_name, options = {}) #:nodoc: 
    super(table_name, @config[:engine].nil? ? options : options.reverse_merge(:options => "ENGINE="[email protected][:engine])) 
    end 
end 


나이 :

:

require 'active_record/connection_adapters/abstract_mysql_adapter' 

module ActiveRecord 
    module ConnectionAdapters 
    class Mysql2Adapter < AbstractMysqlAdapter 
     def create_table(table_name, options = {}) #:nodoc: 
     super(table_name, @config[:engine].nil? ? options : options.reverse_merge(:options => "ENGINE="[email protected][:engine])) 
     end 
    end 
    end 
end 


그런 다음 /config/database.yml 우리는 다음과 같이 할 수 있습니다더 engine은 다음 mysql2 어댑터가 기본 (InnoDB 또는 무엇이든)를 사용합니다 지정하지 않으면

production: 
    adapter: mysql2 
    encoding: utf8 
    database: ooook 
    username: ooook 
    password: ooook 
    host:  ooook.tld 
    port:  3306 
    pool:  5 
    timeout: 5000 
    engine: MyISAM 


.

관련 문제