Skip to content

Instantly share code, notes, and snippets.

@mmmunk
Last active Jan 7, 2022
Embed
What would you like to do?
#!/usr/bin/env bash
set -e
DOCKER_LOG_FILE=/tmp/mysql-dev.log
OUTPUT_LOG_FILE=/tmp/mysql-dev-$(date +%s).log
function StopLog {
echo "Stopping MySQL log"
docker exec dev-db mysql --user=root --execute="set global general_log=0;"
docker exec dev-db rm -f $DOCKER_LOG_FILE
}
echo "Starting MySQL log"
docker exec dev-db rm -f $DOCKER_LOG_FILE
docker exec dev-db mysql --user=root --execute="set global log_output=FILE; set global general_log_file=\"$DOCKER_LOG_FILE\"; set global general_log=1;"
trap StopLog EXIT
echo -n "Run your SQL thing on DEV-DB and press [Enter] when done... "; read -r
docker cp dev-db:$DOCKER_LOG_FILE $OUTPUT_LOG_FILE
echo "Your log file is here:" $OUTPUT_LOG_FILE
-- Log incoming SQL on MySQL server:
set global log_output=FILE;
set global general_log_file="C:/Test/MySQL.log";
set global general_log=1;
-- Turn off:
set global general_log=0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment