Skip to content

Commit 58f8d00

Browse files
authored
Set charset name utf8mb4 by default (#1157)
mysql2 gem dropped testing for MySQL 5.1 which was released in Dec 2008 and already EOL in Dec 2013 at efa47a9. If we no longer support MySQL 5.1, utf8 (utf8mb3) is not appropriate default encoding for MySQL 5.5 or higher, utf8mb4 should be set for that. FYI, Rails 6.0 no longer support MySQL 5.1 and set utf8mb4 by default. rails/rails#33608 rails/rails#33853
1 parent d7d2eee commit 58f8d00

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ Mysql2::Client.new(
273273
:database,
274274
:socket = '/path/to/mysql.sock',
275275
:flags = REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41 | SECURE_CONNECTION | MULTI_STATEMENTS,
276-
:encoding = 'utf8',
276+
:encoding = 'utf8mb4',
277277
:read_timeout = seconds,
278278
:write_timeout = seconds,
279279
:connect_timeout = seconds,
@@ -367,7 +367,7 @@ Use the value `mysql2` as the adapter name. For example:
367367
``` yaml
368368
development:
369369
adapter: mysql2
370-
encoding: utf8
370+
encoding: utf8mb4
371371
database: my_db_name
372372
username: root
373373
password: my_password

lib/mysql2/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def initialize(opts = {})
4545
end
4646
end
4747

48-
# force the encoding to utf8
49-
self.charset_name = opts[:encoding] || 'utf8'
48+
# force the encoding to utf8mb4
49+
self.charset_name = opts[:encoding] || 'utf8mb4'
5050

5151
mode = parse_ssl_mode(opts[:ssl_mode]) if opts[:ssl_mode]
5252
if (mode == SSL_MODE_VERIFY_CA || mode == SSL_MODE_VERIFY_IDENTITY) && !opts[:sslca]

0 commit comments

Comments
 (0)