2
2

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 Ver4.x.x(ver4系列)であいまい検索(LIKE '%...%')できない(日本語・漢字・カタカナ)検索挙動が正確でない問題を解決

Last updated at Posted at 2016-02-08

状況(環境)

  • レンタルサーバー環境下で.ini.conf変更できない
  • phpMyAdminでの操作のみ権限がある。(CUIでアクセスや変更ができない)
  • レンタルサーバー環境下でバージョンアップを期待できない
  • IaaS(AWS等)に移行計画を期待できない

事象

  • 日本語(漢字・カタカナ)をLIKEとワイルドカード(%)を利用した時の検索挙動がおかしい。
(例)
カラム名:name
    :name_kana

データ :name='女性テスト'
    :name_kana='ジョセイテスト'
name LIKE '%女性%' OR name_kana like '%女性%';
→検索OK
name LIKE '%女性テスト%' OR name_kana like '%女性テスト%';
→検索OK
name LIKE '%ジョセイ%' OR name_kana like '%ジョセイ%';
→検索OK
name LIKE '%テスト%' OR name_kana like '%テスト%';
→検索できない
name LIKE '%セイ%' OR name_kana like '%セイ%';
→検索できない

対策

  • LIKE BINARYを使用する
name LIKE '%テスト%' OR name_kana like '%テスト%';

これで解決します。

  • ほかは照合順序などをutf8_general_ciなどにする方法をお試しください。

以上です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?