我安装了
mysqlconnector [ODBC] 5.1.8来运行我的mysql命令,但是我收到了这个错误:
Cannot find type [MySql.Data.MySqlClient.MySqlConnection]: make sure the assembly containing this type is loaded
我应该在PowerShell上安装from the mysql connectors site以运行此命令(或任何MySql命令)?
我在我的系统中安装了最新版本的MySql,所有项目都运行MySql.
最佳答案 您应该安装Connector / Net,它将自己安装在GAC中,并且可以像任何其他.Net程序集一样使用.
然后你可以做,例如
[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