mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
refactor(db_assembler): Allow connecting to non default mysql ports (#3123)
This commit is contained in:
@@ -12,6 +12,8 @@ function dbasm_mysqlExec() {
|
||||
command=$2
|
||||
options=$3
|
||||
|
||||
# MYSQL_PORT needs to be reseted as the next eval might not overwite the current value causing the commands to use wrong port
|
||||
MYSQL_PORT=3306
|
||||
eval $confs
|
||||
|
||||
if [[ ! -z "${PROMPT_USER// }" ]]; then
|
||||
@@ -19,30 +21,31 @@ function dbasm_mysqlExec() {
|
||||
MYSQL_PASS=$PROMPT_PASS
|
||||
fi
|
||||
|
||||
|
||||
export MYSQL_PWD=$MYSQL_PASS
|
||||
|
||||
retval=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" $options -e "$command")
|
||||
retval=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" -P "$MYSQL_PORT" $options -e "$command")
|
||||
if [[ $? -ne 0 ]]; then
|
||||
err=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" $options -e "$command" 2>&1 )
|
||||
err=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" -P "$MYSQL_PORT" $options -e "$command" 2>&1 )
|
||||
if [[ "$err" == *"Access denied"* ]]; then
|
||||
read -p "Insert mysql user:" PROMPT_USER
|
||||
read -p "Insert mysql pass:" -s PROMPT_PASS
|
||||
export MYSQL_PWD=$PROMPT_PASS
|
||||
|
||||
retval=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" $options -e "$command")
|
||||
retval=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" -P "$MYSQL_PORT" $options -e "$command")
|
||||
if [[ $? -ne 0 ]]; then
|
||||
err=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" $options -e "$command" 2>&1 )
|
||||
err=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" -P "$MYSQL_PORT" $options -e "$command" 2>&1 )
|
||||
# it happens on new mysql 5.7 installations
|
||||
# since mysql_native_password is explicit now
|
||||
if [[ "$err" == *"Access denied"* ]]; then
|
||||
echo "Setting mysql_native_password and for $PROMPT_USER ..."
|
||||
sudo -h "$MYSQL_HOST" "$DB_MYSQL_EXEC" -e "UPDATE mysql.user SET authentication_string=PASSWORD('${PROMPT_PASS}'), plugin='mysql_native_password' WHERE User='${PROMPT_USER}'; FLUSH PRIVILEGES;"
|
||||
sudo -h "$MYSQL_HOST" "$DB_MYSQL_EXEC" -P "$MYSQL_PORT" -e "UPDATE mysql.user SET authentication_string=PASSWORD('${PROMPT_PASS}'), plugin='mysql_native_password' WHERE User='${PROMPT_USER}'; FLUSH PRIVILEGES;"
|
||||
fi
|
||||
fi
|
||||
|
||||
# create configured account if not exists
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" $options -e "CREATE USER IF NOT EXISTS '${MYSQL_USER}'@'${MYSQL_HOST}' IDENTIFIED BY '${MYSQL_PASS}' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;"
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" $options -e "GRANT CREATE ON *.* TO '${MYSQL_USER}'@'${MYSQL_HOST}' WITH GRANT OPTION;"
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" $options -P "$MYSQL_PORT" -e "CREATE USER IF NOT EXISTS '${MYSQL_USER}'@'${MYSQL_HOST}' IDENTIFIED BY '${MYSQL_PASS}' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;"
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" $options -P "$MYSQL_PORT" -e "GRANT CREATE ON *.* TO '${MYSQL_USER}'@'${MYSQL_HOST}' WITH GRANT OPTION;"
|
||||
for db in ${DATABASES[@]}
|
||||
do
|
||||
local _uc=${db^^}
|
||||
@@ -54,7 +57,7 @@ function dbasm_mysqlExec() {
|
||||
|
||||
eval $_confs
|
||||
echo "Grant permissions for ${MYSQL_USER}'@'${MYSQL_HOST} to ${_dbname}"
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" $options -e "GRANT ALL PRIVILEGES ON ${_dbname}.* TO '${MYSQL_USER}'@'${MYSQL_HOST}' WITH GRANT OPTION;"
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" $options -P "$MYSQL_PORT" -e "GRANT ALL PRIVILEGES ON ${_dbname}.* TO '${MYSQL_USER}'@'${MYSQL_HOST}' WITH GRANT OPTION;"
|
||||
done
|
||||
else
|
||||
exit
|
||||
@@ -245,6 +248,8 @@ function dbasm_db_backup() {
|
||||
name="DB_"$uc"_NAME"
|
||||
dbname=${!name}
|
||||
|
||||
# MYSQL_PORT needs to be reseted as the next eval might not overwite the current value causing the commands to use wrong port
|
||||
MYSQL_PORT=3306
|
||||
eval $confs;
|
||||
|
||||
if [[ ! -z "${PROMPT_USER// }" ]]; then
|
||||
@@ -252,19 +257,20 @@ function dbasm_db_backup() {
|
||||
MYSQL_PASS=$PROMPT_PASS
|
||||
fi
|
||||
|
||||
|
||||
export MYSQL_PWD=$MYSQL_PASS
|
||||
|
||||
now=`date +%s`
|
||||
|
||||
"$DB_MYSQL_DUMP_EXEC" --opt --user="$MYSQL_USER" --host="$MYSQL_HOST" "$dbname" > "${BACKUP_FOLDER}${database}_backup_${now}.sql" && echo "done"
|
||||
"$DB_MYSQL_DUMP_EXEC" --opt --user="$MYSQL_USER" --host="$MYSQL_HOST" --port="$MYSQL_PORT" "$dbname" > "${BACKUP_FOLDER}${database}_backup_${now}.sql" && echo "done"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
err=$("$DB_MYSQL_DUMP_EXEC" --opt --user="$MYSQL_USER" --host="$MYSQL_HOST" "$dbname" 2>&1 )
|
||||
err=$("$DB_MYSQL_DUMP_EXEC" --opt --user="$MYSQL_USER" --host="$MYSQL_HOST" --port="$MYSQL_PORT" "$dbname" 2>&1 )
|
||||
if [[ "$err" == *"Access denied"* ]]; then
|
||||
read -p "Insert mysql user:" PROMPT_USER
|
||||
read -p "Insert mysql pass:" -s PROMPT_PASS
|
||||
export MYSQL_PWD=$PROMPT_PASS
|
||||
|
||||
"$DB_MYSQL_DUMP_EXEC" --opt --user="$PROMPT_USER" --host="$MYSQL_HOST" "$dbname" > "${BACKUP_FOLDER}${database}_backup_${now}.sql" && echo "done"
|
||||
"$DB_MYSQL_DUMP_EXEC" --opt --user="$PROMPT_USER" --host="$MYSQL_HOST" --port="$MYSQL_PORT" "$dbname" > "${BACKUP_FOLDER}${database}_backup_${now}.sql" && echo "done"
|
||||
else
|
||||
exit
|
||||
fi
|
||||
@@ -294,6 +300,8 @@ function dbasm_db_import() {
|
||||
|
||||
echo "importing $1 - $2 ..."
|
||||
|
||||
# MYSQL_PORT needs to be reseted as the next eval might not overwite the current value causing the commands to use wrong port
|
||||
MYSQL_PORT=3306
|
||||
eval $confs;
|
||||
|
||||
if [[ ! -z "${PROMPT_USER// }" ]]; then
|
||||
@@ -305,18 +313,18 @@ function dbasm_db_import() {
|
||||
|
||||
|
||||
# TODO: remove this line after we squash our DB updates
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" -e "SET GLOBAL max_allowed_packet=128*1024*1024;"
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" --port="$MYSQL_PORT" -e "SET GLOBAL max_allowed_packet=128*1024*1024;"
|
||||
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" --default-character-set=utf8 "$dbname" < "${OUTPUT_FOLDER}${database}_${type}.sql"
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" --port="$MYSQL_PORT" --default-character-set=utf8 "$dbname" < "${OUTPUT_FOLDER}${database}_${type}.sql"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
err=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" "$dbname" 2>&1 )
|
||||
err=$("$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$MYSQL_USER" -P "$MYSQL_PORT" "$dbname" 2>&1 )
|
||||
if [[ "$err" == *"Access denied"* ]]; then
|
||||
read -p "Insert mysql user:" PROMPT_USER
|
||||
read -p "Insert mysql pass:" -s PROMPT_PASS
|
||||
export MYSQL_PWD=$PROMPT_PASS
|
||||
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" "$dbname" < "${OUTPUT_FOLDER}${database}_${type}.sql"
|
||||
"$DB_MYSQL_EXEC" -h "$MYSQL_HOST" -u "$PROMPT_USER" -P "$MYSQL_PORT" "$dbname" < "${OUTPUT_FOLDER}${database}_${type}.sql"
|
||||
else
|
||||
exit
|
||||
fi
|
||||
|
||||
3
conf/dist/config.sh
vendored
3
conf/dist/config.sh
vendored
@@ -164,16 +164,19 @@ DB_MYSQL_DUMP_EXEC="mysqldump"
|
||||
DB_AUTH_CONF="MYSQL_USER='acore'; \
|
||||
MYSQL_PASS='acore'; \
|
||||
MYSQL_HOST='localhost';\
|
||||
MYSQL_PORT='3306';\
|
||||
"
|
||||
|
||||
DB_CHARACTERS_CONF="MYSQL_USER='acore'; \
|
||||
MYSQL_PASS='acore'; \
|
||||
MYSQL_HOST='localhost';\
|
||||
MYSQL_PORT='3306';\
|
||||
"
|
||||
|
||||
DB_WORLD_CONF="MYSQL_USER='acore'; \
|
||||
MYSQL_PASS='acore'; \
|
||||
MYSQL_HOST='localhost';\
|
||||
MYSQL_PORT='3306';\
|
||||
"
|
||||
|
||||
DB_AUTH_NAME="acore_auth"
|
||||
|
||||
Reference in New Issue
Block a user