如何在 Windows 上备份 MySQL 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3823141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to backup MySQL database on Windows?
提问by Misha Moroshko
I have WampServer 2.0 that is installed on Windows on my laptop.
我的笔记本电脑上安装了 WampServer 2.0。
I'm running on it an application that I wrote. The application is working with MySQL database.
我正在运行我编写的应用程序。该应用程序正在使用 MySQL 数据库。
I would like to make backups of this database periodically.
我想定期备份这个数据库。
How this can be done ?
如何做到这一点?
How could I define cron on Windows ?
我如何在 Windows 上定义 cron ?
回答by RichieHindle
The rough equivalent of crontab -e
for Windows is the at
command, as in:
大致相当于crontab -e
Windows 的at
命令是:
at 22:00 /every:M,T,W,Th,F C:\path\to\mysql\bin\mysqldump.exe ...
Running the at
command by itself lists the tasks you've created using at
.
单独运行at
命令会列出您使用at
.
回答by Misha Moroshko
The most popular way to backup MySQL database is to use mysqldump:
备份 MySQL 数据库最流行的方法是使用 mysqldump:
- Open a Windows command line.
Specify the directory to mysqldump utility
cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"
Create a dump of your MySQL database.
- 打开 Windows 命令行。
指定目录到 mysqldump 实用程序
cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"
创建 MySQL 数据库的转储。
mysqldump.exe --user=YourUserName --password=YourPassword --host=localhost --port=3306 --result-file="Pathdump.sql" --databases "DatabaseName"
mysqldump.exe --user=YourUserName --password=YourPassword --host=localhost --port=3306 --result-file="Pathdump.sql" --databases "DatabaseName"
Also, there are a lot of third-party tools, which can perform MySQL backups automatically on a regular basis.
此外,还有很多第三方工具可以定期自动执行 MySQL 备份。
回答by Michael Eakins
You could use a bash script.
您可以使用 bash 脚本。
#!/bin/sh
mysqldump -uroot -ppwd --opt db1 > /sqldata/db1.sql
mysqldump -uroot -ppwd --opt db2 > /sqldata/db2.sql
cd /sqldata/
tar -zcvf sqldata.tgz *.sql
cd /scripts/
perl emailsql.pl