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

【自分メモ】MySQLトラブルシューティング

Last updated at Posted at 2020-03-17

TS01

現象

SQL実行時、以下のエラーが発生。

Syntax error or access violation: 1055 Expression #124 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'カラム名' which is not functionally dependent on columns in GROUP BY clause;this is incompatible with sql_mode=only_full_group_by

解決方法

my.cnfに以下を定義する。

my.cnf
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Dockerを利用している場合

docker-compose.yml
mysql:
  image: mysql:5.7
  command: mysqld --sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
  〜以下省略〜

参考

T02

現象

日本語が文字化けする。

解決方法

my.cnfに以下を定義する。

my.cnf
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

[client]
default-character-set=utf8

Dockerを利用している場合

docker-compose.yml
mysql:
  image: mysql:5.7
  command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci
  〜以下省略〜

参考

TS03

現象

INSERT、UPDATE時に以下のエラーが発生する。

Incorrect string value: '\xF0\xA6\x9A\xB0\xE7\x94...' for column 'my_column' at row 1

解決方法

TS02の対応のみだと、既存テーブルには反映されないので、個別に変更してあげる。

ALTER TABLE <テーブル名> CONVERT TO CHARACTER SET <文字コード>;

参考

3
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
3
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?