0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

utf8とutf8mb4の違い

Posted at

utf8
・簡単に言うと絵文字が使えない
・Unicodeに対応している
①アルファベット、数字、記号などの基本的な文字を表すASCIIコード
②世界中のあらゆる文字(例えばハングル文字やアラビア文字など)を加えた文字の集合体
→これらのことを指す
・世界中に普及している

utf8mb4
・絵文字が使える
・MySQLで扱うための文字コード


アプリ作成時に以下のコマンドを入力すると

% rails new アプリ名 -d mysql

以下のように、デフォルトでdatabase.ymlに「utf8mb4」が記載されている。

例)database.yml

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  socket: /tmp/mysql.sock

utf8を使いたかったら上から三段目を変えれば良い。

default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  socket: /tmp/mysql.sock

以上です。


おまけ
僕のTwitter:https://twitter.com/honaki_days?s=21

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?