Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails 6 MySQLのutf8mb4対応とは何であって何ではないのか

Rails 6 MySQLのutf8mb4対応とは何であって何ではないのか

Yasuo Honda

April 12, 2019
Tweet

More Decks by Yasuo Honda

Other Decks in Technology

Transcript

  1. Key prefix lengthͷ໰୊ͱ͸ • "ERROR 1071 (42000): Specified key was

    too long; max key length is 767 bytes" • Rails string type is mapped to MySQL varchar(255) • 255(characters) x 4(bytes) = 1020 > 767
  2. 5.5 and 5.6 • Add ROW_FORMAT=DYNAMIC option if innodb_file_per_table =

    1 AND innodb_file_format = 'Barracuda' • https://github.com/rails/rails/pull/34742
  3. Priority • ࠷༏ઌ • database.yml default value: encoding: utf8mb4 •

    σϑΥϧτͷdatabase.ymlΛฤूͨ͠৔߹ • options[:collation] • options[:charset] (options[:encoding] ͱಉ͡ҙຯ) • optionsͷࢦఆ͕ͳ͍ & MySQL 5.7.9Ҏ্ • utf8mb4 • optionsͷࢦఆ͕ͳ͍ & MySQL 5.6ҎԼ • "Configure a supported :charset and ensure innodb prefix is enabled to support indexes on varchar(255) string columns."
  4. Since proper collation is language dependent (that is the reason

    that Unicode provide multi level comparison), I personally would not like to provide any collation by default.
  5. I basically answer "Please consider using default collation (utf8mb4_general_ci in

    MySQL 5.7 case). If it has any issue for your use case (Sushi-Beer issue, etc), using utf8mb4_bin might avoid that issue.".