MySQL database Remote Backup / Import


Backup database (MySQL)

Steps:
1. Create a text file text
2. Write the following information
3. After saving, modify the file name extension .bat file
4. Double-click the bat file to run

Examples are as follows:

 


@echo off
@set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"
@set "db_name=test"
D:\MySQL\"MySQL Server 5.5"\bin\mysqldump --opt --complete-insert --max-allowed-packet=1073741824 -u root --password=root -h127.0.0.1 %db_name% > F:\XX\beifenSql\%db_name%_%Ymd%.dump
@echo on
@pause


Information Description:

@echo off @echo on  indicates that the program start and end

@set "db_name = test"     provided db_name a variable whose value is test

D: \ MySQL \ "MySQL Server 5.5" \ bin \ mysqldump  expressed the need to open a command export MySQL database,
which "MySQL Server 5.5" because the file path here has spaces, use double quotation marks to distinguish

--opt   This option represents activated Mysqldump command quick, add-drop-table, add-locks, extended-insert, lock-tables parameter,
that is, by -opt parameters do not need additional export when using Mysql database information Mysqldump these parameters.

--complete-insert  Use complete insert statements

--max-allowed-packet = 1073741824   represented a single data maximum threshold (& MySQL my.ini file is the same size as provided herein, this setting can effectively avoid errors 2020)

-u user name, --password  password, -h127.0.0.1 fixup

% db_name%  expressed using the variable db_name

>  Represents the symbolic

F: \ MM \ beifenSql \% db_name% _% Ymd% .dump   the file to be created

% date: ~, 4 %% date : ~ 5,2 %% date: ~ 8,2% "  represents the current time is obtained by splicing %%,
    such as:% date: ~, 4% obtain the current year,% date: ~ 5,2% to get the current month,% date: ~ 8,2% to get the current date

@pause  is a pause command in the command line window will show the implementation of the "Press any key to continue..." button and wait for you
====================== ==================================================

 


Import dump file:
Open cmd window, enter the following information, press Return,
 
MySQL-uroot--proot the Test <F: \ XX \ beifenSql \ test_20180928.dump

Information Description: MySQL database, -u user name -p password, the Test database name, < symbolic,  
F: \ XX \ beifenSql \ test_20180928.dump    to import the full path of the file

Guess you like

Origin blog.csdn.net/qq_39751996/article/details/82884358