Skip to content

Commit

Permalink
Fix MySQL ONLY_FULL_GROUP_BY
Browse files Browse the repository at this point in the history
  • Loading branch information
pemontto committed Dec 30, 2020
1 parent 0e0c783 commit 850fb2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ services:
# Database Configuration (And their defaults)
# - "MYSQL_HOST=db"
# - "MYSQL_USER=misp"
# - "MYSQL_PASSWORD=example" # NOTE: This should be AlphaNum with no Special Chars. Otherwise, edit config files after first run.
# - "MYSQL_PASSWORD=example" # NOTE: This should be AlphaNum with no Special Chars. Otherwise, edit config files after first run.
# - "MYSQL_DATABASE=misp"
# Optional Settings
# - "MYSQL_ROOT_PASSWORD=password" # Enable to allow fixing ONLY_FULL_GROUP_BY MySQL defaults
# - "NOREDIR=true" # Do not redirect port 80
# - "DISIPV6=true" # Disable IPV6 in nginx
# - "SECURESSL=true" # Enable higher security SSL in nginx
Expand Down
14 changes: 14 additions & 0 deletions server/files/entrypoint_nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ MISP_APP_CONFIG_PATH=/var/www/MISP/app/Config
[ -z "$REDIS_FQDN" ] && REDIS_FQDN=redis
[ -z "$MISP_MODULES_FQDN" ] && MISP_MODULES_FQDN="http://misp-modules"
[ -z "$MYSQLCMD" ] && MYSQLCMD="mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -P $MYSQL_PORT -h $MYSQL_HOST -r -N $MYSQL_DATABASE"
[ -z "$MYSQLROOTCMD" ] && MYSQLROOTCMD="mysql -u root -p$MYSQL_ROOT_PASSWORD -P $MYSQL_PORT -h $MYSQL_HOST -r -N $MYSQL_DATABASE"

ENTRYPOINT_PID_FILE="/entrypoint_apache.install"
[ ! -f $ENTRYPOINT_PID_FILE ] && touch $ENTRYPOINT_PID_FILE
Expand Down Expand Up @@ -92,6 +93,19 @@ init_mysql(){
exit 1
fi

# If we're given the root password, disable the default sql_mode ONLY_FULL_GROUP_BY
# in MySQL. Required until https://github.com/MISP/MISP/issues/1894 is fixed
if [ -n "$MYSQL_ROOT_PASSWORD" ]; then
echo -n "Checking if ONLY_FULL_GROUP_BY mode is enabled..."
sql_mode=$(echo "SELECT @@sql_mode" | $MYSQLROOTCMD | grep "ONLY_FULL_GROUP_BY")
if [ -n "$sql_mode" ]; then
echo -e "\nDisabling MySQL default ONLY_FULL_GROUP_BY"
echo "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));" | $MYSQLROOTCMD 1>/dev/null
else
echo " OK"
fi
fi

if [ $(isDBinitDone) -eq 0 ]; then
echo "Database has already been initialized"
else
Expand Down

0 comments on commit 850fb2d

Please sign in to comment.