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

MySQL Series 13 MySQL Replication

Table of contents 1. MySQL replication related co...

Detailed code examples of seven methods for vertical centering with CSS

When we edit a layout, we usually use horizontal ...

Summary of basic knowledge and operations of MySQL database

This article uses examples to explain the basic k...

Vue integrates Tencent TIM instant messaging

This article mainly introduces how to integrate T...

Steps to export the fields and related attributes of MySQL tables

Need to export the fields and properties of the t...

HTML hyperlinks explained in detail

Hyperlink Hyperlinks are the most frequently used ...

MySQL query statement simple operation example

This article uses examples to illustrate the simp...

Detailed explanation of the basic use of react-navigation6.x routing library

Table of contents react-native project initializa...

Detailed steps to install Docker mongoDB 4.2.1 and collect springboot logs

1: Install mongodb in docker Step 1: Install mong...

JavaScript to achieve stair rolling special effects (jQuery implementation)

I believe everyone has used JD. There is a very c...

Use Xshell to connect to the Linux virtual machine on VMware (graphic steps)

Preface: I recently started to study the construc...

Vue implements horizontal scrolling of marquee style text

This article shares the specific code for Vue to ...

Detailed example of sorting function field() in MySQL

Preface In our daily development process, sorting...