---
title: "window bat脚本 mysql 热备份与恢复 "
author: "toolkit1216"
date: "2011-06-23T16:59:43Z"
tags: ["C", "MySQL", "SQL", "SQL Server", "脚本"]
categories: ["数据库"]
slug: "window-bat-mysql"
draft: false
lastmod: "2011-06-30T16:15:06Z"
id: 1102681
url: "https://toolkit1216.iteye.com/blog/1102681"
---

一： mysql 热备份  
@echo off  
set txt1=%date:~0,4%  
::当前年  
set txt2=%date:~5,2%  
::当前月  
set txt3=%date:~8,2%  
::当前日  
set txt4=%time:~0,2%  
::当前小时  
set txt5=%time:~3,2%  
::当前分钟  
set txt6=%time:~6,2%  
::当前秒  
set date=%txt1%%txt2%%txt3%  
set time=%txt4%%txt5%%txt6%  
::设置当前mysql路径  
set mysql\_path=&quot;C:\\Program Files\\MySQL\\MySQL Server 5.0&quot;  
::设置当前mysql bin路径  
set mysql\_path\_bin=%mysql\_path%\\bin  
::设置opt\_mysql  
set opt\_mysql=--add-drop-database --add-drop-table  
set back\_file=&quot;D:\\MySQLData&quot;  
echo MySQL Database backup  
echo about 10 minutes  
echo don't close this window  
echo it will close by itself  
echo output Database  
:: mysql安装bin路径 %mysql\_path\_bin%\\mysqldump  
:: mysql备份文件路径%back\_file%\\%date%%time%.sql  
::备份test数据库  
ECHO 开始备份test数据库  
if exist %date%%time%.sql del %date%%time%.sql  
%mysql\_path\_bin%\\mysqldump %opt\_mysql% -c -u root -pliyong test &gt; %back\_file%\\%date%%time%.sql  
::将备份的&quot;%date%%time%.sql&quot;进行rar压缩。  
&quot;C:\\Program Files\\WinRAR\\rar&quot; a &quot;D:\\MySQLData\\%date%%time%.sql.rar&quot; &quot;D:\\MySQLData\\%date%%time%.sql&quot;  
:: 删除备份的源文件  
del &quot;D:\\MySQLData\\%date%%time%.sql&quot;  
pause  
\======================================================

window mysq：l 热恢复

@echo off

::文件路径

 D:\\MySQLData\\20110623163403.sql  
mysql -u root -pliyong test