標籤:window mysql 監控 主從
window 平台下mysql主從的監控(window執行計畫配合vb指令碼)
(1)在window上安裝ODBC(vb連結MySQL的驅動程式)
為:http://dev.mysql.com/downloads/connector/odbc/
根據window系統選擇相應版本即可。
我安裝的是mysql-connector-odbc-5.3.4
如果在安裝mysql-connector-odbc-5.3.4報錯了,
Error 1918.Error installing ODBC driver Mysql ODBC 5.3 ANSI Driver,ODBC error 13: 不能載入安裝或轉換器。
Verify that the file MySQL ODBC 5.3 ANSI Driver exists and that you can accessit
那麼就是缺少組件(vcredist_x64.exe),下載安裝就行了。
為 http://pan.baidu.com/s/1bnozwsB
(2) 安裝完mysql-connector-odbc-5.3.4 驅動程式之後就可以利用vb操作資料庫了
以下是一段vb指令碼,主要是用來監控MySQL主從狀態,並發送郵件通知
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‘查看是否串連成功,成功狀態值為1‘msgbox Conn.stateIf Cnn.State = 0 Then ‘msgbox "串連資料庫失敗"else ‘ msgbox "串連資料庫成功"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異常" call CheckFile(TextBody)end if ‘定義一個函數,檢查每天的備份是否產生function CheckFile(byval TextBody ) Const Email_From = "[email protected]" ‘寄件者郵箱 Const Password = "[email protected]" ‘寄件者郵箱密碼 Const Email_To = "[email protected]" ‘收件者郵箱 Set CDO = CreateObject("CDO.Message") ‘建立CDO.Message對象 CDO.Subject = "警告:伺服器10.0.1.20 異常" ‘郵件主題 CDO.From = Email_From ‘寄件者地址 CDO.To = Email_To ‘收件者地址 CDO.TextBody = TextBody ‘郵件內文 ‘cdo.AddAttachment = "C:\hello.txt" ‘郵件附件檔案路徑 Const schema = "http://schemas.microsoft.com/cdo/configuration/" ‘規定必須是這個,我也不知道為什麼 With CDO.Configuration.Fields ‘用with關鍵字減少代碼輸入 .Item(schema & "sendusing") = 2 ‘使用網路上的SMTP伺服器而不是本地的SMTP伺服器 .Item(schema & "smtpserver") = "smtp.163.com" ‘SMTP伺服器位址 .Item(schema & "smtpauthenticate") = 1 ‘伺服器認證方式 .Item(schema & "sendusername") = Email_From ‘寄件者郵箱 .Item(schema & "sendpassword") = Password ‘寄件者郵箱密碼 .Item(schema & "smtpserverport") = 25 ‘SMTP伺服器連接埠 .Item(schema & "smtpusessl") = True ‘是否使用SSL .Item(schema & "smtpconnectiontimeout") = 60 ‘串連伺服器的逾時時間 .Update ‘更新設定 End With CDO.Send ‘發送郵件 End function
本文出自 “SQLServer MySQL” 部落格,請務必保留此出處http://dwchaoyue.blog.51cto.com/2826417/1583978
window 平台下mysql主從的監控(window執行計畫配合vb指令碼)