Mysqdump use and its precautions

mysqldump installation

If you just want to use mysqldump, then you only need to download the mysql client, the server can not be down, my side is ubuntu, centos uses yum (Yam) to manage the package

apt-get install mysql-client

Download 5.7 version of mysql-client and mysql-client-core by default

mysqldump backup several tables of the specified database

You can specify the port number, user name, password, the database to be backed up and the specified file path, such as ip address 192.168.0.1, port number 3306, user name root, password root, database to be backed up default, tables default1 and default2, backup To the file default1_2.sql

mysqldump -h 192.168.0.1 -P 3306 -uroot -proot default default1 default2> /root/backup/default1_2.sql

mysqldump backup several specified databases

Specify the backup database default_1 and default_2 to the file default_1_2.sql

mysqldump -h 192.168.0.1 -P 3306 -uroot -proot --databases default_1 default_2> /root/backup/default_1_2.sql

mysqldump backup all databases

mysqldump -h 192.168.0.1 -P 3306 -uroot -proot --all-databases> /root/backup/all.sql

mysqldump regular backup

Write a simple shell script, cooperate with crontab, execute the script, for example, name the sql file according to timestamp

current = ` date  " +% Y-% m-% d% H:% M:% S " ` 
timeStamp = ` date -d " $ current " +% s` #Convert 
current to timestamp, accurate to millisecond   
currentTimeStamp = $ ((timeStamp * 1000 + ` date  " +% N " ` / 1000000 )) 
name = " _sq.sql "
mysqldump -h 192.168.0.1 -P 3306 -uroot -proot --databases default > /root/backup/`$currentTimeStamp$name`

Use crontab to execute shell files under ubuntu

mysqldump restore data

mysqldump -h 192.168.0.1 -P 3306 -uroot -proot default </root/backup/default.sql #Library must be kept, or empty library

-B parameter backup and restore

After adding the -B option, there will be two operations automatically create database and use database

Details to be studied, there are many options and small operations

 

Guess you like

Origin www.cnblogs.com/YC-L/p/12702556.html