如何在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:20:07  来源:igfitidea点击:

How to backup MySQL database on Windows?

mysqlwindowsbackupwamp

提问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 -efor Windows is the atcommand, as in:

大致相当于crontab -eWindows 的at命令是:

at 22:00 /every:M,T,W,Th,F C:\path\to\mysql\bin\mysqldump.exe ...

Running the atcommand by itself lists the tasks you've created using at.

单独运行at命令会列出您使用at.

The mysqldump documentation is here.

mysqldump的文档是在这里

回答by Misha Moroshko

The most popular way to backup MySQL database is to use mysqldump:

备份 MySQL 数据库最流行的方法是使用 mysqldump:

  1. Open a Windows command line.
  2. Specify the directory to mysqldump utility

    cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"

  3. Create a dump of your MySQL database.

  1. 打开 Windows 命令行。
  2. 指定目录到 mysqldump 实用程序

    cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"

  3. 创建 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

http://paulbradley.tv/38/

http://paulbradley.tv/38/