Skip to content

Commit

Permalink
Set charset name utf8mb4 by default (#1157)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kamipo authored Dec 4, 2024
1 parent d7d2eee commit 58f8d00
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ Mysql2::Client.new(
:database,
:socket = '/path/to/mysql.sock',
:flags = REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41 | SECURE_CONNECTION | MULTI_STATEMENTS,
:encoding = 'utf8',
:encoding = 'utf8mb4',
:read_timeout = seconds,
:write_timeout = seconds,
:connect_timeout = seconds,
Expand Down Expand Up @@ -367,7 +367,7 @@ Use the value `mysql2` as the adapter name. For example:
``` yaml
development:
adapter: mysql2
encoding: utf8
encoding: utf8mb4
database: my_db_name
username: root
password: my_password
Expand Down
4 changes: 2 additions & 2 deletions lib/mysql2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def initialize(opts = {})
end
end

# force the encoding to utf8
self.charset_name = opts[:encoding] || 'utf8'
# force the encoding to utf8mb4
self.charset_name = opts[:encoding] || 'utf8mb4'

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

0 comments on commit 58f8d00

Please sign in to comment.