Mysql backup multiple database code examples

Mysql backup multiple database code examples

This article mainly introduces the Mysql backup multiple database code examples. The sample code is introduced in great detail in this article, which has a certain reference value for everyone's study or work. Friends in need can refer to it.

Backup data script

#!/bin/bash

# date is a command in Linux date [parameter] [+format]
time=`date +%Y_%m_%d_%H_%M_%S`
# Backup output path backupdir=/home/backup/
# Backup file path filedir=/home/my_app/files/
# Use sql statement to retrieve all databases starting with 'test'. Pass the command to the mysql client through the pipeline; -N means not to output the header and end of the result, and the result is a pure data set databases=(`echo 'show databases like "test%";' | mysql -N -uroot -proot`)
# Pass the output file of mysqldump to gzip through the pipe for compression. gzip cannot save the original file and cannot compress the directory. mysqldump -uroot -proot --databases ${databases[*]} | gzip > $backupdir/$time.sql.gz
# Back up files. zip [compressed output file] [compressed file]
zip -r $backupdir/$time.zip $filedir
# Delete the backup file 7 days ago find $backupdir -mtime +7 -name "*" -exec rm -rf {} \;

Then set crontab to run the backup script every morning

Data Recovery

mysql -u root -p DATABESE_NAME < dump.sql

Or connect to mysql client

mysql> source dump.sql

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Notes on the MySQL database backup process
  • Shell script to backup MySQL database data regularly and retain it for a specified time
  • Mysql database scheduled backup script sharing
  • How to implement scheduled backup of CentOS MySQL database
  • MySQL database backup and recovery implementation code
  • MySQL database introduction: detailed explanation of database backup operation
  • Analysis of MySQL data backup and recovery implementation methods
  • MySQL scheduled database backup operation example
  • Summary of various implementation methods of mysql database backup
  • Linux implements scheduled backup of MySQL database and deletes backup files older than 30 days
  • Linux regularly backs up the MySQL database and deletes previous backup files (recommended)
  • Selection and thinking of MySQL data backup method

<<:  The latest super detailed graphic tutorial of installing Kali Linux on virtual machine VMware

>>:  Analysis of the principle and creation method of Mysql temporary table

Recommend

A brief discussion on common operations of MySQL in cmd and python

Environment configuration 1: Install MySQL and ad...

Solution to inserting a form with a blank line above and below

I don't know if you have noticed when making a...

Basic HTML directory problem (difference between relative path and absolute path)

Relative path - a directory path established based...

JavaScript to achieve simple tab bar switching case

This article shares the specific code for JavaScr...

Exploring the Linux Kernel: The Secrets of Kconfig

Get a deep understanding of how the Linux configu...

How to install SVN server under Linux

1. Yum installation yum install subversion 2. Con...

MySQL case when group by example

A mysql-like php switch case statement. select xx...

Common tags in XHTML

What are XHTML tags? XHTML tag elements are the b...

Detailed explanation of writing multiple conditions of CSS: not

The :not pseudo-class selector can filter element...

How to build nfs service in ubuntu16.04

Introduction to NFS NFS (Network File System) is ...

Using HTML web page examples to explain the meaning of the head area code

Use examples to familiarize yourself with the mean...

MySQL database index order by sorting detailed explanation

Table of contents The cause of the incident Anato...