Created
October 19, 2012 20:24
-
-
Save rpherrera/3920498 to your computer and use it in GitHub Desktop.
Import /etc/localtime to MySQL and set its TimeZone to SYSTEM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
user='root' | |
password='default' | |
mysql_bin='mysql' | |
function set_up_bin() { | |
if [ "${user}" == "" ]; then | |
echo "WARNING: user was not set." | |
else | |
mysql_bin="${mysql_bin} -u${user}" | |
fi | |
if [ "${password}" == "" ]; then | |
echo "WARNING: password was not set." | |
else | |
mysql_bin="${mysql_bin} -p${password}" | |
fi | |
mysql_bin="${mysql_bin} -e" | |
} | |
function run_query() { | |
query_result=$(${mysql_bin} "${1}") | |
} | |
echo 'Setting up MySQL calls...' | |
set_up_bin | |
echo 'Importing Sao_Paulo TimeZone from /etc/localtime to MySQL internal database...' | |
mysql_tzinfo_to_sql /etc/localtime Sao_Paulo | mysql -u${user} mysql -p${password} | |
echo 'Getting MySQL TimeZone info from @@global.time_zone and @@session.time_zone internal variables...' | |
run_query 'SELECT @@global.time_zone, @@session.time_zone;' | |
echo ${query_result} | while read not_used not_used session_tz global_tz; do | |
echo -n "@@global.time_zone: " | |
if [ "${global_tz}" == 'SYSTEM' ]; then | |
echo "SYSTEM (OK)" | |
else | |
echo "${global_tz} (WARNING)" | |
echo 'Setting @@global.time_zone to SYSTEM...' | |
run_query 'SET GLOBAL time_zone = SYSTEM;' | |
fi | |
echo -n "@@session.time_zone: " | |
if [ "${session_tz}" == 'SYSTEM' ]; then | |
echo "SYSTEM (OK)" | |
else | |
echo "${session_tz} (WARNING)" | |
echo 'Setting @@global.time_zone to SYSTEM...' | |
run_query 'SET SESSION time_zone = SYSTEM;' | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment