Mysql ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 問題的處理

在使用如下命令:mysql

docker run -p 3306:3306 --name jiuhao-mysql 
-v F:/docker/mysql/datadir:/var/lib/mysql 
-e MYSQL_ROOT_PASSWORD=123456 -d  mysql

啓動mysql後,執行某個sql報以下錯誤:sql

Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_bydocker

所以須要從新配置mysql的配置來規避。bash

使用下面的命令啓動mysql,指定自定義配置的目錄:this

docker run -p 3306:3306 --name jiuhao-mysql 
-v F:/docker/mysql/datadir:/var/lib/mysql 
-v F:/docker/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -d  mysql

其中-v F:/docker/mysql/conf:/etc/mysql/conf.d是關鍵,將宿主機的一個目錄映射到容器中的conf.d目錄,容器中的mysql會加載這個目錄下面全部配置。若是-v 掛載不是了請設置宿主機硬盤共享。以下圖:spa

能夠使用3d

winpty docker exec -it jiuhao-mysql bash

進行/etc/mysql下的目錄查看。rest

接下來在宿主機的F:/docker/mysql/conf的目錄下建立一個mysql的配置文件,名字自定義,這裏仍是使用my.cnf做爲文件名。配置內容以下:code

[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

sql_mode能夠根據本身的須要修改。orm

最後重啓容器:

docker restart jiuhao-mysql

相關文章
相關標籤/搜索