0
0

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 5 years have passed since last update.

MySQLに日本語を入れると、データが???で表示される

Last updated at Posted at 2019-11-17

問題について

前提

meido テーブル こんなかんじのカラム。
スクリーンショット 2019-11-17 15.22.49.png
下記のコマンドで、meidoテーブルにデータを入れる。
ここまではエラーは起きないが、

でデータを参照すると
スクリーンショット 2019-11-17 15.29.10.png

という風に日本語の部分が?????と表示される。

解決方法

テーブルを作る際、VARCHAR を NVARCHAR に置き換える。

エラーの出る書き方

CREATE TABLE meido(id INT,name VARCHAR(100),name_kana VARCHAR(200),prefecture VARCHAR(50),address TEXT,age INT);

エラーを防ぐ書き方はこれ!!!!!!!!!

上述の通り、VARCHAR を NVARCHAR に置き換えます。
CREATE TABLE meido(id INT,name NVARCHAR(100),name_kana NVARCHAR(200),prefecture NVARCHAR(50),address TEXT,age INT);

以上。

mySQLにログインした状態で

と打つと、

Server characterset が latin1

になっていたので、これが原因かも。

参考記事 https://qiita.com/EigenPort_M/items/46bd1bf386eb56eba97e
     https://qiita.com/toshihirock/items/fdbc8e7b889e0d17a18d

追記

言語設定を日本語 utf8mb4 に設定したら VARCHAR指定でもきちんと表示されるようになった。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?