MySQL common backup commands and shell backup scripts sharing

MySQL common backup commands and shell backup scripts sharing

To back up multiple databases, you can use the following command:

mysqldump -uroot -p123456 --databases test1 test2 test3 > /home/test/dump.sql;

To restore a backup:

source dump.sql -- Enter this command in the MySQL command line to restore

Back up the entire database:

mysqldump -uroot -123456 -A > all.sql

Back up the entire database structure:

mysqldump -uroot -p123456 -P3306 -A -d > all_002.sql

Back up a single database structure and its data

mysqldump -uroot -p123456 -P3306 test > all_003.sql

Back up a single database structure and its data

mysqldump -uroot -p123456 -P3306 test -d > all_004.sql

Backing up a single database

mysqldump -uroot -p123456 -P3306 test -t > all_005.sql

Generally speaking, the structure and data of the backup database are more commonly used in actual production environments. In the era of big data, data is crucial. Through data analysis, certain user behaviors can be discovered, thereby opening up the market.

The backup shell script content is as follows:

#!/bin/bash
base_dir=/home/test/sql_script
DATE=$(date +%Y%m%d)
time=$(date "+%Y-%m-%d %H:%M:%S")
cd $base_dir
mysqldump -uroot -p123456 --databases eluzhupms lms > dump$DATE.sql

if [ $? -eq 0 ]
then
 echo "Successfully backed up mysql database, current date:"$time >> /home/test/mysql_dump.log

else

 echo "Backup of mysql database failed: Current date is: "$time>> /home/test/mysql_dump.log

fi

The above is the details of the commonly used MySQL backup commands and shell backup scripts. For more information about MySQL backup, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Shell script to monitor MySQL master-slave status
  • How to install MySQL 5.7.29 with one click using shell script
  • Shell script to backup MySQL database data regularly and retain it for a specified time
  • Shell script automates the creation of basic configuration of virtual machines: tomcat--mysql--jdk--maven
  • Shell script to implement mysql scheduled backup, deletion and recovery functions
  • A small Shell script to accurately count the number of rows in each Mysql table
  • Create MySQL database accounts on the server in batches through Shell scripts
  • How to add index to mysql using shell script
  • Kill a bunch of MySQL databases with just a shell script like this (recommended)
  • How to use shell scripts to automatically back up multiple MySQL databases every day
  • Introduction and installation of MySQL Shell

<<:  JS implements user registration interface function

>>:  How to run Linux commands in the background

Recommend

Data Structure - Tree (III): Multi-way Search Tree B-tree, B+ tree

Multi-way search tree Height of a complete binary...

How to use rem adaptation in Vue

1. Development environment vue 2. Computer system...

js uses FileReader to read local files or blobs

Table of contents FileReader reads local files or...

User experience analysis of facebook dating website design

<br />Related article: Analysis of Facebook&...

What kinds of MYSQL connection queries do you know?

Preface If the query information comes from multi...

How webpack implements static resource caching

Table of contents introduction Distinguish betwee...

How to insert a link in html

Each web page has an address, identified by a URL...

Summary of the three stages of visual designer growth

Many people have read this book: "Grow as a ...

Detailed explanation of Linux command unzip

Table of contents 1. unzip command 1.1 Syntax 1.2...

MySQL learning database operation DML detailed explanation for beginners

Table of contents 1. Insert statement 1.1 Insert ...

Centos7 installation of Nginx integrated Lua sample code

Preface The computer I use is a Mac, and the oper...