标签:mysql powershell
1、在使用PowerShell操作MySQL之前,需要下载MySQL Connector Net 6.9.5(自行度娘)
2、下载安装后,需要找到其安装的目录,并找到用于连接和操作MySQL的DLL文件;如:
C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.5\Assemblies\v2.0\MySql.Data.dll(V2.0为NET的版本)
3、核心语句为:
[void][system.Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.5\Assemblies\v2.0\MySql.Data.dll") | Out-Null
连接MySQL:
$Server="127.0.0.1" $Database="sql_" $user="root" $Password= "" $charset="utf8" $connectionString = "server=$Server;uid=$user;pwd=$Password;database=$Database;charset=$charset" $connection = New-Object MySql.Data.MySqlClient.MySqlConnection($connectionString) $connection.Open()
执行SQL:
$insertsql = "INSERT INTO jiaban(加班时间,加班时长,加班原因) VALUES(‘XXX‘,‘XXX‘,‘XXX‘);" $insertcommand = New-Object MySql.Data.MySqlClient.MySqlCommand $insertcommand.Connection=$connection $insertcommand.CommandText=$insertsql $insertcommand.ExecuteNonQuery()
关闭连接:
$connection.Close()
本文出自 “AiCCDD” 博客,请务必保留此出处http://520ccdd.blog.51cto.com/3926314/1708002
标签:mysql powershell
原文地址:http://520ccdd.blog.51cto.com/3926314/1708002