1
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: sql_mode=only_full_group_byについて

Posted at

まずはエラー文章をご覧ください。

Error: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘dbnam.tablename.columnname’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

ローカル環境で、上記のようなエラーが出ることがあります。
これはselect文の書き方が間違っている、というようなエラーです。

SQL文に、
group by (色々) という書き方で書いてしまうと、そんな書き方は許可されてないそうです。
MySQL5.7以降は、そういうのを許可してないみたいです。

sql_mode=only_full_group_by

このような機能がデフォルトでオンになっています。
なので、どうするかというとsql_modeを空っぽにしておけば良いです。

# docker-compose.yml
~~(中略)〜〜
  ### MySQL ##################################
  mysql:
    image: mysql:5.7
    command: --max_allowed_packet=32505856      # Set max_allowed_packet to 256M (or any other value)
    environment:
      MYSQL_ROOT_PASSWORD: xxxx
      MYSQL_DATABASE: xxxxxxdb
      MYSQL_USER: xxuser
      MYSQL_PASSWORD: xxxxxxxxxxxx
    volumes:
      - mysql-database:/var/lib/mysql
    ports:
      - 43306:3306
    networks:
      - backend
    command: --sql_mode="" ←コレ

ドッカーを落として上げてみたいなことをします。

$ docker-compose down
$ docker-compose up -d

コレでこのエラーは回避できます。

参考リンク:
http://muchag.undo.jp/archives/3487

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