当前位置:网站首页>Multi database and multi table backup and restore of MySQL under Linux
Multi database and multi table backup and restore of MySQL under Linux
2022-06-25 20:55:00 【Gem, Chaochao】
One 、 Write a bash Script files
1、 Create directory
Create a file directory in the root directory
1) The scripts directory
[[email protected] /]#mkdir scripts/
2) Backup file directory
[[email protected] /]#mkdir -p server/backup/
2、 establish bash Script files
[[email protected] /]#cd /scripts/
[[email protected] scripts]#vim mysqldump1.sh
The contents of the document are as follows :
#!bin/bash
USER=root
PASSWD=root
SOCKET=/software/mysql/mysql.sock
LOGIN="mysql -u$USER -p$PASSWD -S $SOCKET"
DUMP="mysqldump --no-defaults -u$USER -p$PASSWD -S $SOCKET"
DATABASE=$($LOGIN -e "show databases;"|egrep -v "*chema|mysql|sys"|sed '1d')
for database in $DATABASE
do
TABLE=$($LOGIN -e "use $database;show tables;"|sed '1d')
for table in $TABLE
do
[ -d /server/backup/$database ] || mkdir /server/backup/$database -p
$DUMP $database $table |gzip >/server/backup/$database/${database}_${table}_$(date +%F).sql.gz
done
done
3、 Perform backup operations
[[email protected] /]#cd /scripts/
[[email protected] scripts]#sh mysqldump1.sh
Two 、 Extract files and restore databases
[[email protected] /]# cd /server/backup/
[[email protected] backup]# ll
Total usage 0
drwxr-xr-x. 2 root root 109 4 month 30 15:29 test_interface
[[email protected] backup]# cd test_interface/
[[email protected] test_interface]# ll
Total usage 4
-rw-r--r--. 1 root root 855 4 month 30 15:29 test_interface_config_total_2021-04-30.sql.gz
[[email protected] test_interface]#gunzip <test_interface_config_total_2021-04-30.sql.gz | mysql -uroot -proot test_interface
mysql: [Warning] Using a password on the command line interface can be insecure.
边栏推荐
- Usage Summary of str.format() function [not 'str****{}'.Format()]
- Tencent music knowledge map search practice
- [golang] leetcode intermediate - the kth largest element in the array &
- Yolov4 reading notes (with mind map)! YOLOv4: Optimal Speed and Accuracy of Object Detection
- The live registration is hot to start | the first show of Apache dolphin scheduler meetup in 2022!
- Patrol script
- Desktop network error display red ×, Component failed to start
- Lesson 3 urllib
- About eruake learning
- Splunk series: Splunk installation and deployment (I)
猜你喜欢
MySQL installation tutorial
Literals and type conversions of basic data types

Installing mysql8 under centos8

Compile 6relayd using the cross compiler
2022 "gold, silver and four" is a must for job hopping. You must know 100 questions in 2022 intermediate and advanced Android interview to realize your big factory dream
![[summary] 2021unctf Campus (cry & MISC)](/img/b1/8c4fb9c6d4f1b89361c0487762cdbd.jpg)
[summary] 2021unctf Campus (cry & MISC)
Feature Engineering in simple terms – a practice guide based on openmldb (Part 1)

Install JDK, MySQL and nexus under Linux (tar package installation)
2022 oceanbase technical essay contest officially opened | come and release your force

Several ways to obtain domain administrator privileges
随机推荐
Bank digital transformation layout in the beginning of the year, 6 challenges faced by financial level structure and Countermeasures
laf. JS - open source cloud development framework (readme.md)
Yunzhisheng atlas supercomputing platform: computing acceleration practice based on fluid + alluxio (Part I)
同花顺炒股软件开户是合法的吗?安全吗
VFS appears when mounting a file system from an SD card: cannot open root device "mmcblk1p2“
SaaS privatization deployment scheme
CSDN sign in cash reward
Global netizens Yuanxiao created a picture of appreciating the moon together to experience the creativity of Baidu Wenxin big model aigc
Mysqldumpslow out slow statements in the database
The live registration is hot to start | the first show of Apache dolphin scheduler meetup in 2022!
Great changes in the interaction between people and the digital world
Install JDK, MySQL and nexus under Linux (tar package installation)
Recommend a free screen recording software
The super easy-to-use test tool sorted out by Ali P8 for a week
Popular understanding of deviation and variance in machine learning
Cloud development practice of the small program for brushing questions in the postgraduate entrance examination - page design and production (home page of the question bank, ranking page, my)
OLED driven learning based on ssd1306 (II): addressing mode of ssd1306
Shell scripts: Variables
Log4j2 vulnerability battle case
1.0-mq getting started and using