MySQL Database backup automatically on a windows server

后端 未结 5 1565
一向
一向 2020-12-24 05:48

Is there a way to back up MySQL database automatically at certain times of the day for designated servers or send an email with an attachment.. Which ever do you think is th

5条回答
  •  长情又很酷
    2020-12-24 06:46

    databaseW.2016,06,29-22,31,48-15.sql

    @echo off
    rem Backup Database (Daily,via Task Scheduler)
    rem databaseW
    set filename="c:\xampp\dbk\databaseW.%date:~6,4%,%date:~0,2%,%date:~3,2%-%time:~0,2%,%time:~3,2%,%time:~6,2%-%time:~9,2%.sql"
    c:\xampp\mysql\bin\mysqldump.exe --user=root --password=dell@root --host=localhost --port=3306 --result-file=%filename% --default-character-set=utf8 --single-transaction=TRUE --databases "databaseW"
    

    To create file whose name is based on the date and time, use %date% and %time%. Note that the 2 variables are based on locale and cmd shell version

    • open the cmd windows
    • input echo %time% and echo %date% mine is 22:11:16.80,06/29/2016 Wed
    • substr the variable through %variable:~startpos,length% I want the time delimited by comma, so the cmd goes echo %time:~0,2%,%time:~3,2%,%time:~6,2%,%time:~9,2%
    • to get a filename like databaseW.2016,06,29-22,31,48-15.sql use set filename="databaseW.%date:~6,4%,%date:~0,2%,%date:~3,2%-%time:~0,2%,%time:~3,2%,%time:~6,2%-%time:~9,2%.sql"
    • check the date and time in advance
    • use the --result-file option instead of >; According to the Mysql Manuel, the charset of file saved using ">" is UTF-16, while the --result-file follows the --default-character-set
    • save to file BackpDay-databaseW.cmd
    • add it to a new task Action and set a trigger (Windows Task Scheduler)

提交回复
热议问题