PowerShell操纵MySQL

 

 

#导入操作MySQL库
$mySQLDataDLL = "C:\Scripts\GetMonitor\MySQL.Data.dll"
[void][system.reflection.Assembly]::LoadFrom($mySQLDataDLL)

#定义连接MySQL相关信息
$Server="10.10.16.2"
$Database="monitor"
$table = "windows"
$user="monitor" 
$Password= "EW" 
$charset="utf8"
$connectionString = "server=$Server;uid=$user;pwd=$Password;database=$Database;charset=$charset"
$connection = New-Object MySql.Data.MySqlClient.MySqlConnection($connectionString)
$connection.Open()

$sqlcmd = "INSERT INTO $table(item,value) VALUES(""$item"",$value);"
$insertcmd = New-Object MySql.Data.MySqlClient.MySqlCommand
$insertcmd.Connection=$connection
$insertcmd.CommandText=$sqlcmd
$insertcmd.ExecuteNonQuery()

$connection.Close()

 

posted on 2021-12-07 17:13  momingliu11  阅读(330)  评论(0编辑  收藏  举报