Mysql backup failure case (1)
Mysql backup failure case (1)
Environment:
OS: windows server 2012
DB:Mysql5.7.17
Question:
Mysql can make a successful automatic backup at 22:00 every night through the mysqldump command.
After 9: 00 in the morning, the automatic backup of bat files was performed separately. The backup reported an error. The error message is as follows:
C:\ Users\ Administrator > rem * * backup Start**
Mysqldump: [Warning] Using a password on the command line interface can be insec ure.
Mysqldump: Couldn't find table: "9-29-04.sql"
Error: the file was not found using the specified search criteria.
C:\ Users\ Administrator > rem * * backup End**
Problem analysis:
In the backup script, use% date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%-%time:~6,2% to get the current time, because there may be multiple backups in a day in the format of "year-month-day-hour-minute-second"
By reporting the error "mysqldump: Couldn't find table:" 9-29-04.sql ", we can see that there was a problem when using% time:~0,2% to get.
The problem reappears:
When the Cmd window executes echo% date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%, it is found that there is an extra space before hour 9, which causes the backup to fail.
C:\ Users\ Administrator > echo% date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
2018-11-29-9-28-17
But it's normal to get hours from 10:00, and there are no extra spaces:
C:\ Users\ Administrator > echo% date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%
2018-11-29-12-29-54
The cause of the problem:
Get the hour through% time:~0,2%. If the current hour is in single digits, that is, 0-9 o'clock, a space will appear before the hour:
C:\ Users\ Administrator > echo% time:~0,2%
nine
C:\ Users\ Administrator > echo% time:~0,2%
twelve
Solution:
Replace the space before the hour with 0
C:\ Users\ Administrator > set hackers% timeconfusion 0. 2%
C:\ Users\ Administrator > set hashes% h: = 0%
C:\ Users\ Administrator > echo% date:~0,4%-%date:~5,2%-%date:~8,2%-%h%-%time:~3,2%-%time:~6,2%
2018-11-29-09-28-55
Welcome to follow my Wechat official account "IT Little Chen" and learn and grow together!