Help us understand the problem. What is going on with this article?

mysqlで日本語を扱えるようにする

More than 1 year has passed since last update.

mysqlで日本語を使って怒られた人向けの記事

こんなエラーが出た人向け

エラー例
ERROR 1366 (HY000): Incorrect string value: '\xE3\x82\xBF\xE3\x82\xA4...' for column 'title' at row 1

現在の状態を確認する

任意のユーザでログインして、statusコマンド

コマンド例
# mysql -u minato -p

(パスワードを入力)  

mysql> status

   mysql  Ver 14.14 Distrib 5.7.21, for Linux (x86_64) using  EditLine wrapper
   ~~
   Server characterset:    utf8
   Db     characterset:    utf8
   Client characterset:    utf8
   Conn.  characterset:    utf8
   ~~

上記が全部utf-8になってない人は設定する

/etc/my.cnf
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqldump]
default-character-set=utf8

[mysqld]
character-set-server=utf8

使ってるOSによって置いてあるディレクトリは違うと思う
(上記はCentOS7)の例

再起動する

# systemctl restart mysqld.service

注意:文字コード設定はDB毎にもある

一旦、日本語を扱えない文字コードで作ったDBはstatusを見れば分かる通り、日本語が扱えないままになってる。作り直せば解決だけども、文字コードくらい変更できると思う(そこまでは調べてない、もし調べたら追記します)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした