简体   繁体   中英

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:

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.

The code basically loops over all databases and creates a .sql file containing all structure and data for each database.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 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.

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..

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.

Code is copied from here: 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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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