1. 程式人生 > >windows mysql備份資料庫及清除過期資料

windows mysql備份資料庫及清除過期資料

檢視資料庫使用的儲存引擎

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的為預設儲存引擎。 

 備份所有資料庫

D:\Program Files\MariaDB 10.3\bin>mysqldump -u root -h localhost -p --all-databases > d:\mysqldbback\all.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