Mysql automatically backs up and sends emails to the specified email address bitsCN.com.
First, write the export command
Used
Mysqladmin ping
Mysqldump
Then add the attachment and send it to the email.
The corresponding com
Last pause to check the situation
Refer:
Http://hi.baidu.com/zd8695/blog/item/ae50b21c4b398a8087d6b6ac.html
See the program:
@ Echo on
: Mysql directory and the corresponding drive letter and the drive letter and path of the current bat file
Set MYSQL_HOME = H:/wamp/bin/mysql/mysql5.5.16/bin
Set MYSQL_DIR = H:
Set EXECUTE_DIR = C:
Set EXECUTE_HOME = C:/Users/fartpig/Desktop
: Email account password
Set EMAIL_ACCOUNT = ****** @ 126.com
Set EMAIL_PASS = ******
Echo start
Echo save path
Echo % cd %
Set CURRENT_DIR = % cd %
Echo export SQL
% MYSQL_DIR %
Cd % MYSQL_HOME %
Echo try mysql
Mysqladmin ping
Mysqldump-u root-proot plane> plane. SQL
Echo send mail
% EXECUTE_DIR %
Cd % CURRENT_DIR %
Start % EXECUTE_HOME %/mail. vbs % EMAIL_ACCOUNT % EMAIL_PASS % MYSQL_HOME %/plane. SQL
Echo send success
Pause
Corresponding mail. vbs
Function Send_mail (You_Account, You_Password, Send_Email, Send_Email2, Send_Topic, Send_Body, Send_Attachment)
'Code by NetPatch Changed by ZD8695
'Vbs mail sending parameter descriptions
'You _ account': Your email Account
'You _ Password: your email Password
'Send _ Email:
'Main email address
'Send _ Email2: alternate email address
'Send _ Topic:
'Subject
'Send _ Body:
'Mail content
'Send _ Attachment: email Attachment
You_ID = Split (You_Account, "@",-1, vbTextCompare)
'Account and server separation
MS_Space = "http://schemas.microsoft.com/cdo/configuration"
'This is a must, but you can rest assured that you will not send emails through Microsoft.
Set Email = CreateObject ("CDO. Message ")
Email. From = You_Account
'This must be the same as the email sending account.
Email. To = Send_Email
'Main email address
If Send_Email2 <> "Then
Email. CC = Send_Email2
'Backup email address
End If
Email. Subject = Send_Topic
'Subject
Email. Textbody = Send_Body
'Mail content
If Send_Attachment <> "" Then
Email. AddAttachment Send_Attachment
'Email attachment
End If
With Email. Configuration. Fields
. Item (MS_Space & "sendusing") = 2
'Mail Port
. Item (MS_Space & "smtpserver") = "smtp." & You_ID (1)
'Smtp server address
. Item (MS_Space & "smtpserverport") = 25
'Smtp server port
. Item (MS_Space & "smtpauthenticate") = 1
'Cdobasec
. Item (MS_Space & "sendusername") = You_ID (0)
'Your email account
. Item (MS_Space & "sendpassword") = You_Password
'Your email password
. Update
End
Email. Send
'Send email
Set Email = Nothing
'Close the component
Send_Mail = True
'If no error message exists, the message is sent successfully. Otherwise, the message fails to be sent.
If Err Then
Err. Clear
Send_Mail = False
End If
End Function
If Send_Mail (wscript. arguments (0), wscript. arguments (1), wscript. arguments (0), "", "database plane backup", "View attachment", wscript. arguments (2) = True Then
Wscript. Echo "sent successfully"
Else
Wscript. Echo "failed to send"
End If
Note: You can modify the content in the corresponding comment, which includes four parameters and two mailbox-related
Bat directory and drive letter
Mail. vbs directory and drive letter
In addition, you can modify the email address and password and send the code to other mailboxes. Note that 126 is easy to use and some other mailboxes are not excluded ..
BitsCN.com