Last active
August 24, 2022 22:08
-
-
Save mxyq/65b176673f72dec04f6b2d8e9f37f333 to your computer and use it in GitHub Desktop.
[MySQL] #Bash #MySQL
This file contains hidden or 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
config_mysqld() { | |
_info "Change MySQL Password ..." | |
db_pass="" | |
${mysql_location}/bin/mysqld --initialize-insecure --user=mysql >>/var/log/initialize.log 2>&1 | |
${mysql_location}/bin/mysql_ssl_rsa_setup | |
/usr/local/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"${db_pass}\" with grant option;" | |
/usr/local/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"${db_pass}\" with grant option;" | |
/usr/local/bin/mysql -uroot -p${db_pass} -e "grant all privileges on *.* to root@'%' identified by \"${db_pass}\" with grant option;" | |
_info "Import SQL File ..." | |
/usr/local/bin/mysql -uroot -p${db_pass} 2>/dev/null << EOF | |
source $work_dir/jenkins_pipeline/mysql57/init.sql | |
EOF | |
} |
This file contains hidden or 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
mysql_backup() { | |
if [ -z "${MYSQL_ROOT_PASSWORD}" ]; then | |
log "MySQL root password not set, MySQL backup skipped" | |
exit 1 | |
fi | |
mysql -u root -p"${MYSQL_ROOT_PASSWORD}" 2>/dev/null << EOF | |
exit | |
EOF | |
if [ "$?" -ne "0" ]; then | |
log "MySQL all databases backup failed" | |
exit 1 | |
fi | |
mysqldump -u root -p"${MYSQL_ROOT_PASSWORD}" "$1" > "${SQL_FILE}" 2>/dev/null | |
log "MySQL ""$1"" databases dump file name: ${SQL_FILE}" | |
} | |
mysql_backup "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment