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:
|
<<: 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
Transactions in MySQL are automatically committed...
Table of contents 1. Number in JavaScript 2. Math...
1. [admin@JD ~]$ cd opt #Enter opt in the root di...
1. What is MySQL master-slave synchronization? Wh...
Overview In actual business scenario applications...
A dynamic clock demo based on Canvas is provided ...
The data backup operation is very easy. Execute t...
Table of contents Use Cases Reactive API related ...
Table of contents need Workaround 1. Set tooltip ...
Let’s take a look first. HTML source code: XML/HT...
The detailed installation process of mysql5.7.21 ...
Table of contents Hidden, descending, and functio...
Preface This article records a common SMS verific...
What is wxs? wxs (WeiXin Script) is a scripting l...
Table of contents 1. Scene introduction 2 Code Op...