我应该安装哪个驱动程序才能使用 powershell 运行 mysqlcommand?

发布于 2024-10-19 17:34:50 字数 394 浏览 3 评论 0原文

我安装了 mysqlconnector [ODBC] 5.1.8 来运行 mysqlcommand,但出现此错误:

Cannot find type [MySql.Data.MySqlClient.MySqlConnection]: make sure the assembly containing this type is loaded

我应该安装哪个驱动程序 从 mysql 连接器站点 在 powershell 上运行此命令(或任何 MySql 命令)?

我的系统中安装了最新版本的 MySql,并且所有项目都使用 MySql 运行得很好。

I installed the mysqlconnector [ODBC] 5.1.8 for running my mysqlcommand, but I got this error:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不如归去 2024-10-26 17:34:50

您应该安装 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

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.

[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
蹲在坟头点根烟 2024-10-26 17:34:50

对于运行 Powershell 2.0 并使用 .NET 4 的任何收到此错误的人来说,过程略有不同。您仍然需要 .NET 连接器。

您需要在 $pshome 目录中创建一个配置文件,以允许 Powershell 与 .NET 4 程序集一起运行。 这个答案提供了一个适当的解决方案,并且评论中提供了一些针对 64 位计算机的有用信息。

如果您在使用 LoadWithPartialName 时遇到问题...事实证明它自 Powershell 3.0 起已弃用 。此替代方案适用于 2 和 3,并且可能更容易排除故障,因为它是 cmdlet:

Add-Type -Path '$path\MySql.Data.dll'

其中 $path 是 MySql.Data.dll 所在的目录。

For anyone receiving this error that is running Powershell 2.0 and using .NET 4, the procedure is slightly different. You will still need the .NET connector.

You will need to create a config file in the $pshome directory to allow Powershell to run with .NET 4 assemblies. This answer provides an appropriate solution to do so, and the comments have some helpful information for 64-bit machines.

If you are experiencing trouble with LoadWithPartialName... turns out it is deprecated as of Powershell 3.0. This alternative will work in both 2 and 3, and may be a bit easier to troubleshoot since it is a cmdlet:

Add-Type -Path '$path\MySql.Data.dll'

Where $path is the directory that MySql.Data.dll is located.

青朷 2024-10-26 17:34:50

把这个文件MySql.Data.dll
在 powershell.exe 所在的目录中

put this file MySql.Data.dll
in directory where powershell.exe is residing

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文