Skip to content

Instantly share code, notes, and snippets.

@mxyq
Last active August 24, 2022 22:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxyq/65b176673f72dec04f6b2d8e9f37f333 to your computer and use it in GitHub Desktop.
Save mxyq/65b176673f72dec04f6b2d8e9f37f333 to your computer and use it in GitHub Desktop.
[MySQL] #Bash #MySQL
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
}
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