Skip to content

Instantly share code, notes, and snippets.

@floehopper
Last active December 20, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floehopper/6131069 to your computer and use it in GitHub Desktop.
Save floehopper/6131069 to your computer and use it in GitHub Desktop.
MySQL UTF-8 charset and collation
pp ActiveRecord::Base.connection.select("SHOW VARIABLES LIKE 'character%';").to_hash
# =>
[
{"Variable_name"=>"character_set_client", "Value"=>"utf8"},
{"Variable_name"=>"character_set_connection", "Value"=>"utf8"},
{"Variable_name"=>"character_set_database", "Value"=>"utf8"},
{"Variable_name"=>"character_set_filesystem", "Value"=>"binary"},
{"Variable_name"=>"character_set_results", "Value"=>"utf8"},
{"Variable_name"=>"character_set_server", "Value"=>"utf8"},
{"Variable_name"=>"character_set_system", "Value"=>"utf8"},
{"Variable_name"=>"character_sets_dir", "Value"=>"/usr/local/Cellar/mysql/5.5.29/share/mysql/charsets/"}
]
pp ActiveRecord::Base.connection.select("SHOW VARIABLES LIKE 'collation%';").to_hash
# =>
[
{"Variable_name"=>"collation_connection", "Value"=>"utf8_general_ci"},
{"Variable_name"=>"collation_database", "Value"=>"utf8_unicode_ci"},
{"Variable_name"=>"collation_server", "Value"=>"utf8_unicode_ci"}
]
# The values of the following variables don't really matter:
# `character_set_filesystem`
# `character_set_system`
# `character_sets_dir`
# You may see `collation_server` set to `utf8_general_ci`.
# But as long as it's a `utf8` collation it doesn't really matter.
# If you want to be as close to production as possible, then you may want to add the following to your MySQL configuration:
# /usr/local/etc/my.cnf (for homebrew installs)
# [mysqld]
# character-set-server=utf8
# collation-server=utf8_unicode_ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment