备份命令以 MySQL 8.0 为例:
说明:
- user, pass, dbname 改成相应的数据;
- 备份路径 "D:\backup\",可修改;
- MySQL 8.0 的安装目录通常为 "C:\Program Files\MySQL\MySQL Server 8.0",如有变更可修改;
- 命令可以保存为 "backup.bat" 由其他程序方便调用。
命令:
bash
@echo off
set host=127.0.0.1
set port=3306
set user=root
set pass=password
set dbname=aloveric
set backup_date=%date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
set backupfile=D:\backup\%dbname%-%backup_date%.sql
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump" -h%host% -P%port% -u%user% -p%pass% -c --add-drop-table %dbname% > %backupfile%