From eb335c9a95b7992b15f833856c7849b4379d23b1 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 10 Dec 2018 16:32:47 +0100 Subject: [PATCH] create_database.sh, max_memory_limit_mysql.sh: use configuration file 'mysql_credetials.conf'. --- create_database.sh | 114 ++++++++++++++++++++------------------ max_memory_limit_mysql.sh | 40 ++++++------- 2 files changed, 79 insertions(+), 75 deletions(-) diff --git a/create_database.sh b/create_database.sh index 6c6a350..44af3c2 100755 --- a/create_database.sh +++ b/create_database.sh @@ -3,7 +3,7 @@ working_dir="$(dirname $(realpath $0))" log_dir="${working_dir}/log" -conf_file="${working_dir}/conf/create_drop_database.conf" +conf_file="${working_dir}/conf/mysql_credetials.conf" tmp_log_file="$(mktemp)" @@ -277,8 +277,11 @@ else warn "No Configuration File found. Loading defaults.." fi -[[ -n "$MYSQL_CREDENTIAL_ARGS" ]] || MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS" -#[[ -n "$ACTION" ]] || ACTION="$DEFAULT_ACTION" +if [[ -n "$mysql_credential_args" ]]; then + MYSQL_CREDENTIAL_ARGS="$mysql_credential_args" +else + MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS" +fi if ! $NON_INTERACTIVE_MODE ; then @@ -464,59 +467,60 @@ else echo_ok fi -if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] ; then - - echononl " Grant usage to user '$DATABASE_USER' (Creates User..)" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ - "GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 - if [[ $? -ne 0 ]] ; then - echo_failed - error "$(cat $tmp_log_file)" - else - echo_ok - fi - - echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME'" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ - "GRANT ALL PRIVILEGES ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'localhost'" > $tmp_log_file 2>&1 - if [[ $? -ne 0 ]] ; then - echo_failed - error "$(cat $tmp_log_file)" - else - echo_ok - fi - - if $ACCESS_FROM_OUTSIDE ; then - - for _ip in $IP_ADDRESSES ; do - - echononl " Grant usage to user '$DATABASE_USER' access from ${_ip}" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ - "GRANT USAGE ON *.* TO '$DATABASE_USER'@'${_ip}' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 - if [[ $? -ne 0 ]] ; then - echo_failed - error "$(cat $tmp_log_file)" - else - echo_ok - fi - - echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME' from $_ip" - mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ - "GRANT ALL PRIVILEGES ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'${_ip}'" > $tmp_log_file 2>&1 - if [[ $? -ne 0 ]] ; then - echo_failed - error "$(cat $tmp_log_file)" - else - echo_ok - fi - - done - - fi - -elif [[ $MAJOR_VERSION -gt 8 ]] \ +#if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] ; then +# +# echononl " Grant usage to user '$DATABASE_USER' (Creates User..)" +# mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +# "GRANT USAGE ON *.* TO '$DATABASE_USER'@'localhost' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 +# if [[ $? -ne 0 ]] ; then +# echo_failed +# error "$(cat $tmp_log_file)" +# else +# echo_ok +# fi +# +# echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME'" +# mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +# "GRANT ALL PRIVILEGES ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'localhost'" > $tmp_log_file 2>&1 +# if [[ $? -ne 0 ]] ; then +# echo_failed +# error "$(cat $tmp_log_file)" +# else +# echo_ok +# fi +# +# if $ACCESS_FROM_OUTSIDE ; then +# +# for _ip in $IP_ADDRESSES ; do +# +# echononl " Grant usage to user '$DATABASE_USER' access from ${_ip}" +# mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +# "GRANT USAGE ON *.* TO '$DATABASE_USER'@'${_ip}' IDENTIFIED BY '$DATABASE_PASSWD'" > $tmp_log_file 2>&1 +# if [[ $? -ne 0 ]] ; then +# echo_failed +# error "$(cat $tmp_log_file)" +# else +# echo_ok +# fi +# +# echononl " Grant all privileges to user '$DATABASE_USER' on Database '$DATABASE_NAME' from $_ip" +# mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +# "GRANT ALL PRIVILEGES ON ${DATABASE_NAME}.* TO '$DATABASE_USER'@'${_ip}'" > $tmp_log_file 2>&1 +# if [[ $? -ne 0 ]] ; then +# echo_failed +# error "$(cat $tmp_log_file)" +# else +# echo_ok +# fi +# +# done +# +# fi +# +#elif [[ $MAJOR_VERSION -gt 8 ]] \ +if [[ "$MYSQL_CUR_DISTRIBUTION" = "MySQL" ]] && ([[ $MAJOR_VERSION -gt 8 ]] \ || ( [[ $MAJOR_VERSION -eq 8 ]] && [[ $MINOR_VERSION -gt 0 ]] ) \ - || ( [[ $MAJOR_VERSION -eq 8 ]] && [[ $MINOR_VERSION -eq 0 ]] && [[ $PATCH_LEVEL -ge 3 ]] ) ; then + || ( [[ $MAJOR_VERSION -eq 8 ]] && [[ $MINOR_VERSION -eq 0 ]] && [[ $PATCH_LEVEL -ge 3 ]] )) ; then # - Use (password) plugin mysql_native_password # - diff --git a/max_memory_limit_mysql.sh b/max_memory_limit_mysql.sh index b0a7e9c..e856b9e 100755 --- a/max_memory_limit_mysql.sh +++ b/max_memory_limit_mysql.sh @@ -3,7 +3,7 @@ working_dir="$(dirname $(realpath $0))" log_dir="${working_dir}/log" -conf_file="${working_dir}/conf/create_drop_database.conf" +conf_file="${working_dir}/conf/mysql_credetials.conf" tmp_log_file="$(mktemp)" @@ -18,7 +18,7 @@ if [[ -f "$conf_file" ]]; then source "$conf_file" > $tmp_log_file 2>&1 fi -[[ -n "$MYSQL_CREDENTIAL_ARGS" ]] || MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS" +[[ -n "$mysql_credential_args" ]] || mysql_credential_args="$DEFAULT_MYSQL_CREDENTIAL_ARGS" declare -i key_buffer_size @@ -35,47 +35,47 @@ declare -i join_buffer_size declare -i thread_stack declare -i binlog_cache_size -key_buffer_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +key_buffer_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'key_buffer_size'" | awk '{print$2}'` -query_cache_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +query_cache_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'query_cache_size'" | awk '{print$2}'` -tmp_table_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +tmp_table_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'tmp_table_size'" | awk '{print$2}'` -innodb_buffer_pool_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +innodb_buffer_pool_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'innodb_buffer_pool_size'" | awk '{print$2}'` -innodb_additional_mem_pool_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +innodb_additional_mem_pool_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'innodb_additional_mem_pool_size'" | awk '{print$2}'` -innodb_log_buffer_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +innodb_log_buffer_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'innodb_log_buffer_size'" | awk '{print$2}'` -max_connections=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +max_connections=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'max_connections'" | awk '{print$2}'` -sort_buffer_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +sort_buffer_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'sort_buffer_size'" | awk '{print$2}'` -read_buffer_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +read_buffer_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'read_buffer_size'" | awk '{print$2}'` -read_rnd_buffer_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +read_rnd_buffer_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'read_rnd_buffer_size'" | awk '{print$2}'` -join_buffer_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +join_buffer_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'join_buffer_size'" | awk '{print$2}'` -thread_stack=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +thread_stack=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'thread_stack'" | awk '{print$2}'` -binlog_cache_size=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +binlog_cache_size=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'binlog_cache_size'" | awk '{print$2}'` -mysql_version=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +mysql_version=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'version'" | awk '{print$2}' | sed -e's/-.*$//'` -mysql_version_compile_machine=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +mysql_version_compile_machine=`mysql $mysql_credential_args -N -s -e \ "SHOW VARIABLES LIKE 'version_compile_machine'" | awk '{print$2}'` declare -i max_used_connections declare -i uptime declare -i threads_connected -max_used_connections=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +max_used_connections=`mysql $mysql_credential_args -N -s -e \ "SHOW STATUS LIKE 'Max_used_connections'" | awk '{print$2}'` -threads_connected=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +threads_connected=`mysql $mysql_credential_args -N -s -e \ "SHOW STATUS LIKE 'Threads_connected'" | awk '{print$2}'` -uptime=`mysql $MYSQL_CREDENTIAL_ARGS -N -s -e \ +uptime=`mysql $mysql_credential_args -N -s -e \ "SHOW STATUS LIKE 'Uptime'" | awk '{print$2}'` _now=`date +%s`