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 1 year has passed since last update.

MySQL 4バイトの絵文字を保存できるようにする

Posted at

用途

MySQLで4バイトの絵文字を保存できるようにしたい時に使う。
(MySQL5.5以上の環境)

文字コードがutf8に設定されている場合は、4バイトの絵文字は保存できません。

すでにテーブルがある場合に4バイトの絵文字を使えるようにする方法

文字コードを utf8mb4 に設定する。

現在のテーブルの文字コードの設定を確認する方法

show テーブル名 like "chara%";

テーブルの文字コードの設定を変更する方法

alter table テーブル名 default character set utf8mb4;

 

これからテーブルを場合に4バイトの絵文字を使えるようにする方法

テーブル作成の際に、DEFAULT CHARSET=utf8mb4 を設定する。

CREATE TABLE hoge_table (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
hoge_id int(10) unsigned NOT NULL,
hoge text,
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 comment='ほげほげ';

DEFAULT CHARSET
テーブル全体に文字コードを指定するオプション。

テーブル作成について
https://qiita.com/marukome/items/1e359bdc2a91f52bf875

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?