Here's a simple script that demonstrates Powershell access to MySQL.
| [void][system.reflection.Assembly]::LoadFrom("C:\Program Files\MySQL\MySQL Connector Net 5.2.3\Binaries\.NET 2.0\MySQL.Data.dll") |
| |
| $myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection |
| $myconnection.ConnectionString = "server=localhost;user id=root;password=password;database=mysql;pooling=false" |
| $myconnection.Open() |
| |
| $mycommand = New-Object MySql.Data.MySqlClient.MySqlCommand |
| $mycommand.Connection = $myconnection |
| $mycommand.CommandText = "SHOW TABLES" |
| |
| $myreader = $mycommand.ExecuteReader() |
| |
| while($myreader.Read()){ $myreader.GetString(0) } |
| |
| $myreader.Close() |
| |
| $myconnection.Close() |