简体   繁体   English

使用mysqldump.exe进行MySQL完整备份

[英]MySQL full backup with mysqldump.exe

set dateStr=%date:~-7,2%-%date:~-10,2%-%date:~-4,4%
"C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin\mysqldump.exe" -u user -p password --all-

databases  --single-transaction --flush-logs --master-data=2 > full_backup_%dateStr%.sql

it works for another server we have. 它适用于我们拥有的另一台服务器。 this is a new server but with the same database. 这是一台新服务器,但是具有相同的数据库。 It only creates a 1 KB file with the content: 它只会创建一个1 KB的文件,其内容如下:

Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

please help. 请帮忙。

Found this question when I was trying to get my own Mysql database backed up and thought I'd share how I ended up doing it. 当我尝试备份自己的Mysql数据库时,发现了这个问题,并以为我将分享自己最终的做法。

The code basically loops over all databases and creates a .sql file containing all structure and data for each database. 该代码基本上遍历所有数据库,并创建一个.sql文件,其中包含每个数据库的所有结构和数据。

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: MySQL Backup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: MySQl DB user
set dbuser=BackupUser

:: MySQl DB users password
set dbpass=BackUpUserPassWord

:: Switch to the MySQL data directory and collect the folder names
pushd "C:\Server\databases\mysql\data"

:: Loop through the folders and use the file names for the sql files, collects all databases automatically this way
:: Pass each name to mysqldump.exe and output an individual .sql file for each

FOR /D %%F IN (*) DO (
  "C:\Program Files\MySQL\bin\mysqldump.exe" --user=%dbuser% --password=%dbpass% --databases %%F > "C:\Server\backups\mysql\%%F.%TODAY%.sql"
)

To answer your specific question, check to see if you are running the script as administrator and that the user you are trying to backup using has relevant privileges to the databases. 要回答您的特定问题,请检查您是否以管理员身份运行脚本,以及您尝试使用的备份用户是否具有数据库相关权限。 I was stuck on this very problem until I ran my bat file as administrator. 在以管理员身份运行bat文件之前,我一直处于这个问题上。

To check if its a user problem, try running the mysqldump with the root user and see if that helps, if it does you know its a problem with database rights.. 要检查它是否是用户问题,请尝试以root用户运行mysqldump,看看是否有帮助,如果您知道它与数据库权限有关。

To run as administrator right click the bat file, and select Run as administrator, and don't forget to set the checkbox "run with highest privileges" in the scheduled task if you are using that. 要以管理员身份运行,请右键单击bat文件,然后选择“以管理员身份运行”,并且不要忘记在计划的任务中设置“以最高权限运行”复选框。

Code is copied from here: http://www.syntaxwarriors.com/2012/backup-up-a-windows-server-using-only-free-tools/ 代码从此处复制: http : //www.syntaxwarriors.com/2012/backup-up-a-windows-server-using-only-free-tools/

I testes your code and it worked. 我测试了您的代码,它起作用了。 I think you should check again your bat file for any syntax mistake. 我认为您应该再次检查bat文件是否存在语法错误。

set dateStr=%date:~-7,2%-%date:~-10,2%-%date:~-4,4%
"D:\Sync\Apps\Wamp\bin\mysql\mysql5.5.20\bin\mysqldump.exe" -u root --all-databases  --single-transaction --flush-logs --master-data=2 > full_backup_%dateStr%.sql

I removed the -pPASSWORD part because there is no password for root on my local server. 我删除了-pPASSWORD部分,因为本地服务器上没有root用户的密码。 So, if you're going to C/P it from here, don't forget to change mysqldump's path and to add that -p part. 因此,如果要从此处进行C / P,请不要忘记更改mysqldump的路径并添加-p部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM