Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MySQLと文字コードの話
Search
nombom7
January 22, 2020
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
MySQLと文字コードの話
nombom7
January 22, 2020
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
360
Ruling the World: When Life Gets Gamed
codingconduct
0
250
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
170
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
560
Building AI with AI
inesmontani
PRO
1
1.1k
Optimising Largest Contentful Paint
csswizardry
37
3.7k
How to Ace a Technical Interview
jacobian
281
24k
Speed Design
sergeychernyshev
33
1.8k
Designing Experiences People Love
moore
143
24k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
390
Transcript
MySQLと文字コードの話 ぼんばー
自己紹介
ASP.NET(VB.NET)データベース ぼんばー Skill 工場向け生産制御システム開発会社(2017/04~) Work 28 Age 本名 自己紹介 @nom_bom
野村 晃聖
Laravelなんもわからん (DBならなんとか。。。)
という訳で DBの話をします
事前調査
Laravel MySQL Laravel Postgres 日本 世界 直近1年間のGoogle検索数の推移
Twitterのアンケート
という訳で MySQLの話をします
MySQLの文字コード
MySQLには2種類の設定項目がある ・charset ・collation 文字コード 照合順序
charset
文字集合 エンコーディング
文字集合 エンコーディング 規格 実装(符号化) charset JIS X 0208 JIS X
0201 US-ASCII Shift-JIS EUC-JP Windows-31J sjis ujis cp938 複数の文字集合を組み合わせ MySQLの世界
ごちゃごちゃしとる
救世主 Unicode
Unicode 文字集合 エンコーディング UTF-8 UTF-16 規格 実装(符号化) … あまり使われない 文字集合の組み合わせ不要
UTF-32
Unicode(UTF-8)一択 色々あるけど ですよね?
でも
charset MySQLにはUTF-8のcharsetが2種類ある utf8 utf8mb4 1文字1~3バイト 1文字1~4バイト こっちが 常識!
utf8mb4にしましょう 特に理由がなければ charset 絵文字も使えます
collation
collation どの文字を等しいとするか? ・大文字/小文字 ・濁音/半濁音/カナ ・絵文字 A:a は:ば:ぱ:ハ:バ:パ : ・拗音 や:ゃ
コレーション;照合順序
utf8mb4_unicode_ci charset 照合規則 _ci _cs Case Sensitive Case Insensitive 大文字/小文字を区別する
大文字/小文字を区別しない collation 例)
照合規則 A:a : は:ば:ハ や:ゃ general_ci = = ≠ ≠
bin ≠ ≠ ≠ ≠ unicode_ci = = = = unicode_520_ci = ≠ = = 引用元:Qiita記事「寿司ビール問題① 初心者→中級者へのSTEP20/25」
Laravelの話
./config/database.php の初期値
None
collation A:a : は:ば:ハ や:ゃ general_ci = = ≠ ≠
bin ≠ ≠ ≠ ≠ unicode_ci = = = = unicode_520_ci = ≠ = = これ
設定方法
'collation' => 'utf8mb4_bin', $table->collation = 'utf8mb4_bin’; $table-> string('columnName’)-> Collate(‘utf8mb4_bin’); ①
② ③ ./config/database.php ./database/migrations/[ファイル名].php DB TABLE カラム
目的に応じて適切な charset collation を設定しましょう
ありがとうございました