sql_log.sh
Par PlaceOweb le samedi, septembre 19 2015, 19:15 - SQL - Lien permanent
Petit script pour activer les logs des requêtes SQL (MariaDB, MySQL).
Usage :
./sql_log.sh OFF
./sql_log.sh ON
tail -f /var/lib/mysql/hostname.log
~# vim sql_log.sh
#!/bin/bash #echo $1 #echo $* #echo $@ #echo $# # Le nombre d'arguments : $# #echo $# var_on_off=""; if [ $# = 1 ] then if [ $1 = "ON" ] then var_on_off=$1; elif [ $1 = "OFF" ] then var_on_off=$1; else echo "Un seul ARG : ON/OFF"; exit 0; fi else echo "Un seul ARG : ON/OFF"; exit 0; fi var_general_log=`mysql --defaults-file=/etc/mysql/debian.cnf --skip-column-names -A information_schema -e "SELECT VARIABLE_VALUE FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'general_log'"` echo $var_general_log # general_log ON | OFF var_general_log_file=`mysql --defaults-file=/etc/mysql/debian.cnf --skip-column-names -A information_schema -e "SELECT VARIABLE_VALUE FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'general_log_file'"` echo $var_general_log_file # vmp090.log var_datadir=`mysql --defaults-file=/etc/mysql/debian.cnf --skip-column-names -A information_schema -e "SELECT VARIABLE_VALUE FROM GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'datadir'"` echo $var_datadir echo "general_log:" $var_general_log $var_datadir$var_general_log_file if [ $1 = "ON" ] then :>$var_general_log_file fi mysql --defaults-file=/etc/mysql/debian.cnf --skip-column-names -e "SET GLOBAL general_log = $var_on_off" echo "tail -f $var_datadir$var_general_log_file"