Turn on the General Log on a MySQL Container on Demand

I use the following snippet to turn on the MySQL general_log inside my development MySQL containers to peek what is going on: ./mysql-general-log.sh container

#!/bin/bash

# Usage: ./mysql-general-log.sh [container_name]
# This script sets MySQL general logging in a specified Docker container, tails the log, 
# and then disables general logging.

# Default container name if not provided as an argument
CONTAINER=mysql-container

# If a container name is provided as an argument, use that instead
if [ ! -z "$1" ]; then
    CONTAINER=$1
fi

docker exec -it $CONTAINER sh -c 'mysql -uroot -h 127.0.0.1 -e "SET GLOBAL general_log_file=\"/tmp/mysql-genneral.log\";" -e "SET GLOBAL general_log=1"'
docker exec -it $CONTAINER sh -c 'tail -f /tmp/mysql-genneral.log'
docker exec -it $CONTAINER sh -c 'mysql -uroot  -h 127.0.0.1 -e "SET GLOBAL general_log=0"'