安装mysql
后在其根目录下有bin/mysqldump.exe
,本教程备份mysql
数据库就是用这个来备份的。
1. 先在任意目录创建文件db_back.bat
2. 编辑内容
@echo off
set yy=%date:~0,4%
set mm=%date:~5,2%
set dd=%date:~8,2%
if /i %time:~0,2% lss 10 set hh=0%time:~1,1%
if /i %time:~0,2% geq 10 set hh=%time:~0,2%
set mn=%time:~3,2%
set ss=%time:~6,2%
set date=%yy%%mm%%dd%
set time=%hh%%mn%%ss%
set filename=%date%%time%
set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"
"D:\MySoftWare\mysql-8.0.20-winx64\bin\mysqldump" -uroot -p*** halodb> E:\db_backup\halodb\halodb_%filename%.sql
"D:\MySoftWare\mysql-8.0.20-winx64\bin\mysqldump" -uroot -p*** halodb1> E:\db_backup\halodb1\halodb1_%filename%.sql
"D:\MySoftWare\mysql-8.0.20-winx64\bin\mysqldump" -uroot -p*** kodbox> E:\db_backup\kodbox\kodbox_%filename%.sql
"D:\MySoftWare\mysql-8.0.20-winx64\bin\mysqldump" -uroot -p*** nacos_config> E:\db_backup\nacos_config\nacos_config_%filename%.sql
"D:\MySoftWare\mysql-8.0.20-winx64\bin\mysqldump" -uroot -p*** senziyu_blog> E:\db_backup\senziyu_blog\senziyu_blog_%filename%.sql
"D:\MySoftWare\mysql-8.0.20-winx64\bin\mysqldump" -uroot -p*** slimmeryu_blog> E:\db_backup\slimmeryu_blog\slimmeryu_blog_%filename%.sql
@echo on
3. 可在一个脚本中备份多个数据库,去对应的目录查找备份的数据即可,定义了很多变量,用来针对不同的场景
备份视图等信息
mysqldump --all-databases --routines --events -uroot -p> localnew11.sql