Velmi snadno …
Nejprve je potřeba nainstalovat MySQL Connector Net.
A potom už jen …
[void][system.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.16\Assemblies\v4.5.2\MySQL.Data.dll") $MySQLConnection = New-Object MySql.Data.MySqlClient.MySqlConnection $MySQLConnection.ConnectionString = "server=[MySQLserver];uid=[userName];pwd=[userPassword];database=[DBname];pooling=false" $MySQL = New-Object MySql.Data.MySqlClient.MySqlCommand $MySQL.Connection = $MySQLConnection $MySQLConnection.Open() $MySQL.CommandText = "DELETE FROM tabulka" $MySQL.ExecuteNonQuery() $MySQLConnection.Close() |
Taky někdy někdo něco potřebuje z databáze vydolovat:
[void][system.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.16\Assemblies\v4.5.2\MySQL.Data.dll") $MySQLConnection = New-Object MySql.Data.MySqlClient.MySqlConnection $MySQLConnection.ConnectionString = "server=[MySQLserver];uid=[userName];pwd=[userPassword];database=[DBname];pooling=false" $MySQLDataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter $MySQLDataSet = New-Object System.Data.DataSet $MySQL = New-Object MySql.Data.MySqlClient.MySqlCommand $MySQL.Connection = $MySQLConnection $MySQLConnection.Open() $MySQL.CommandText = 'SELECT * FROM tabulka' $MySQLDataAdapter.SelectCommand = $MySQL $NumberOfDataSets = $MySQLDataAdapter.Fill($MySQLDataSet, "data") foreach($radek in $MySQLDataSet.tables[0]){ foreach( $item in $radek ){ $item } } # a nebo třeba foreach($radek in $MySQLDataSet.tables[0]){ $radek.jmeno + ' ' + $radek.prijmeni } $MySQLConnection.Close() |
Nebo něco podobného, jak je ctěná libost…