Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Rails 3 run in MySQL MyISAM mode, without InnoDB?

I have a MySQL server running with InnoDB disabled (for reasons of performance), with this setup I can't seem to be able to use Rails 3 (with the mysql2 adapter).

Here's my test migration:

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

And here's the error:

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

Tried the workaround described here, but it doesn't seem to work either (I did modify MysqlAdapter to Mysql2Adapter to match my setup).

Sorry I'm a newb in Rails. Any help will be much appreciated :o

like image 327
rustyx Avatar asked Dec 13 '22 06:12

rustyx


2 Answers

Going to answer my own question. Here's a patch for environment.rb I ended up with that works with the native mysql driver as well as 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 now succeeds and creates all tables including schema_migrations with TYPE=MyISAM.

Note: For mysql2 adapter, rename mysql_adapter to mysql2_adapter and MysqlAdapter to Mysql2Adapter.

like image 102
rustyx Avatar answered Feb 08 '23 11:02

rustyx


Try creating the table without specifying the type of engine being used like this

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

and then in mysql cli, type this

ALTER TABLE txts ENGINE = MYISAM

hope it helps

like image 31
Hishalv Avatar answered Feb 08 '23 13:02

Hishalv