windows mysql备份数据库及清除过期数据(bat脚本)

查看数据库使用的存储引擎

MariaDB [(none)]> show engines \G;
*************************** 1. row ***************************
      Engine: CSV
     Support: YES
     Comment: Stores tables as CSV files
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 2. row ***************************
      Engine: MRG_MyISAM
     Support: YES
     Comment: Collection of identical MyISAM tables
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 3. row ***************************
      Engine: MEMORY
     Support: YES
     Comment: Hash based, stored in memory, useful for temporary tables
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 4. row ***************************
      Engine: MyISAM
     Support: YES
     Comment: Non-transactional engine with good performance and small data foot
print
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 5. row ***************************
      Engine: SEQUENCE
     Support: YES
     Comment: Generated tables filled with sequential values
Transactions: YES
          XA: NO
  Savepoints: YES
*************************** 6. row ***************************
      Engine: InnoDB
     Support: DEFAULT
     Comment: Supports transactions, row-level locking, foreign keys and encrypt
ion for tables
Transactions: YES
          XA: YES
  Savepoints: YES
*************************** 7. row ***************************
      Engine: Aria
     Support: YES
     Comment: Crash-safe tables with MyISAM heritage
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 8. row ***************************
      Engine: PERFORMANCE_SCHEMA
     Support: YES
     Comment: Performance Schema
Transactions: NO
          XA: NO
  Savepoints: NO
8 rows in set (0.001 sec)

ERROR: No query specified

Support:DEFAULT的为默认存储引擎。 

InnoDB(默认数据库引擎)

 备份所有数据库

D:\Program Files\MariaDB 10.3\bin>mysqldump -u root -h localhost -p --all-databases > d:\mysqldbback\all.sql

 备份指定数据库

D:\Program Files\MariaDB 10.3\bin>mysqldump -u root -h localhost -p singledatabase > d:\mysqldbback\singledatabase.sql

还原所有数据库

MariaDB [(none)]> source d:\mysqldbback\all.sql

自动备份脚本

@echo off  

color 0D  

MODE con: COLS=71 LINES=25 

title mysql数据库自动备份脚本(任务计划)--脚本作者:荆盼

set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"

set "obj_dir= d:\mysqldbback"

md %obj_dir%



@echo 开始备份数据库。

mysqldump -u root -h localhost -proot --all-databases  > %obj_dir%\%Ymd%all.sql

@echo 删除七天前备份的文件。

forfiles /p "d:\mysqldbback" /s /m *.* /d -7 /c "cmd /c del @path"

@echo 数据库备份完成,3秒后程序退出。

ping /n 3 127.0.0.1 >nul

exit
@echo off  
 
color 0D  
 
MODE con: COLS=71 LINES=25 
 
title mysql数据库自动备份脚本(任务计划)--脚本作者:荆盼
 
set "Ymd=%Date:~0,4%%Date:~5,2%%Date:~8,2%%Time:~0,2%%Time:~3,2%%Time:~6,2%"
 
set "obj_dir= c:\mysqlback"
 
md %obj_dir%
 
 
 
@echo 开始备份数据库。
 
mysqldump -u root -h localhost -proot --all-databases  > %obj_dir%\%Ymd%all.sql
 
@echo 删除2天前备份的文件。
 
forfiles /p "c:\mysqlback" /s /m *.* /d -2 /c "cmd /c del @path"
 
@echo 数据库备份完成,10秒后程序退出。
 
ping /n 10 127.0.0.1 >nul
 
exit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值