create_database.sh, max_memory_limit_mysql.sh: use configuration file 'mysql_credetials.conf'.

This commit is contained in:
Christoph 2018-12-10 16:32:47 +01:00
parent 5221328f91
commit eb335c9a95
2 changed files with 79 additions and 75 deletions

View File

@ -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
# -

View File

@ -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`