"MySQL schema/
migration should default
to CHARSET=utf8mb4”
by DHH
rails/rails#33596
Slide 11
Slide 11 text
"Use utf8mb4 character
set by default for MySQL
database #33608”
by yahonda
rails/rails#33608
Slide 12
Slide 12 text
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
Slide 13
Slide 13 text
Key prefix length
Ͳ͏ͬͯղܾ͞Ε͔ͨ
Slide 14
Slide 14 text
5.7 and 8.0
• innodb_default_row_format ͕༗ޮͳͷͰͦͷ··
Slide 15
Slide 15 text
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
Slide 16
Slide 16 text
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."
Slide 17
Slide 17 text
What about collation?
Slide 18
Slide 18 text
Rails 6 does not have
any “default collation”
Slide 19
Slide 19 text
https://github.com/
rails/rails/issues/
33596
Slide 20
Slide 20 text
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.
Slide 21
Slide 21 text
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.".