Question:
I installed the mysqlconnector [ODBC] 5.1.8 for running my mysqlcommand, but I got this error:
1 2 |
Cannot find type [MySql.Data.MySqlClient.MySqlConnection]: make sure the assembly containing this type is loaded |
Which driver should I install from the mysql connectors site to run this command (or any MySql command) on powershell?
I have the latest version of MySql installed in my system and all projects run with MySql very well.
Answer:
You should install the Connector/Net , it installs itself in the GAC, and is available like any other .Net assembly .
Then you can do e.g.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data") $connectionString = "server=myserver;uid=myuser;pwd=mypass;database=mydb;" $connection = New-Object MySql.Data.MySqlClient.MySqlConnection $connection.ConnectionString = $connectionString $connection.Open() $sql = "show tables" $command = New-Object MySql.Data.MySqlClient.MySqlCommand($sql, $connection) $dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command) $table = New-Object System.Data.DataTable $recordCount = $dataAdapter.Fill($table) echo $table echo $table | ogv |