1, before using PowerShell operation MySQL, need to download MySQL Connector Net 6.9.5 (self-degree Niang)
2, download the installation, you need to find the directory of its installation, and find to connect and operate MySQL DLL files, such as:
C:\Program Files (x86) \mysql\mysql Connector net 6.9.5\assemblies\v2.0\mysql.data.dll (V2.0-NET version)
3, the core statement is:
[void] [System. Reflection.assembly]::loadfrom ("C:\Program Files (x86) \mysql\mysql Connector Net 6.9.5\assemblies\v2.0\ MySql.Data.dll ") | Out-null
To connect to MySQL:
$Server = "127.0.0.1" $Database = "sql_" $user = "root" $Password = "$charset =" UTF8 "$connectionString =" server= $Server; uid= $user;p wd= $Password;d atabase= $Database charset= $charset "$connection = New-object MySql.Data.MySqlClient.MySqlConnection ($connectionString) $connection. Open ()
Execute SQL:
$insertsql = "INSERT into Jiaban (overtime, overtime, overtime reason) VALUES (' xxx ', ' xxx ', ' xxx ');" $insertcommand = New-object Mysql.data.mysqlclient.mysqlcommand$insertcommand. connection= $connection $insertcommand. commandtext= $insertsql $insertcommand. ExecuteNonQuery ()
To close the connection:
$connection. Close ()
This article is from the "AICCDD" blog, make sure to keep this source http://520ccdd.blog.51cto.com/3926314/1708002
How to use PowerShell to operate MySQL