MySQL master-slave monitoring under Window Platform (Window execution plan with VB script)
(1) Install ODBC (VB link MySQL driver) on window
is: http://dev.mysql.com/downloads/connector/odbc/
Select the appropriate version according to the window system.
I'm installing mysql-connector-odbc-5.3.4.
If the installation mysql-connector-odbc-5.3.4 error,
Error 1918.Error installing ODBC Driver Mysql ODBC 5.3 ANSI DRIVER,ODBC Error 13: Cannot load installation or converter.
Verify that the file MySQL ODBC 5.3 ANSI Driver exists and that can accessit
So that is the missing component (Vcredist_x64.exe), download the installation is OK.
To Http://pan.baidu.com/s/1bnozwsB
(2) After installing the mysql-connector-odbc-5.3.4 driver, we can use VB to operate the database.
The following is a VB script, mainly used to monitor MySQL master and slave status, and send mail notification
Dim cnndim rstdim strcnn dim status,textbodystrcnn= "Provider=MSDASQL.1; persist security info=true; Extended properties= ' driver=mysql odbc 5.3 ansi driver; server=10.0.1.20; Uid=root; Pwd=root;database=mysql; port=3306 ' "Set cnn = createobject (" ADODB. Connection ") cnn.open strcnn ' to see if the connection is successful, the success status value is 1 ' msgbox conn.stateif cnn.state = 0 then ' msgbox ' connection to database failed ' else ' msgbox ' Connection database succeeded "End ifset rst =createobject (" ADODB. Recordset ") rst.open " Select variable_value from information_schema. global_status where variable_name = ' slave_running ' ", Cnn status=rst (" VARIABLE_VALUE ") .value if status <> "on" then textbody = "Master-slave exception" call checkfile (textbody) end if ' defines a function to check whether daily backups generate funCtion checkfile (byval textbody ) Const Email_From = "[Email protected] " Sender mailbox Const Password = [email protected]" ' Sender mailbox password Const Email_To = ' [email protected] ' ' recipient mailbox set cdo = createobject ("CDO. Message ") ' Create Cdo.message object cdo. subject = "Warning: Server 10.0.1.20 exception" "message subject &NBSP;CDO. from = email_from ' Sender address cdo. to = email_to ' recipient address cdo. textbody = textbody ' message body ' CDO. addattachment = "C:\hello.txt" "Mail attachment file path Const schema = "/HTTP/ schemas.microsoft.com/cdo/configuration/" " must be this, I do not know why &NBSP;WITH&NBSP;CDO. configuration.fields ' use with keyword to reduce code input . Item (schema & "sendusing") = 2 ' use the SMTP server on the network instead of the local SMTP server . Item (schema & "smtpserver") = "smtp.163.com" "SMTP server address . Item (schema & "smtpauthenticate") = 1 ' server authentication mode . Item (schema & "Sendusername") = Email_From ' sender mailbox . Item (schema & "Sendpassword") = Password ' sender's mailbox password . Item (schema & "Smtpserverport") = 25 ' SMTP server port . Item (schema & "Smtpusessl") = True ' whether to use ssl . Item (schema & "smtpconnectiontimeout") = 60 ' connection server timeout time . update ' Update settings end with cdo. send ' Send mail end function
This article is from the "SQL Server MySQL" blog, so be sure to keep this source http://dwchaoyue.blog.51cto.com/2826417/1583978
MySQL master-slave monitoring under Window Platform (Window execution plan with VB script)