在PowerShell中使用加密密码连接到MySQL

时间:2019-04-27 11:02:29

标签: mysql powershell

在通过PowerShell连接到MySQL数据库时,我试图避免在连接字符串上暴露密码,但出现以下错误:

  

使用“ 0”参数调用“打开”的异常:“使用方法'mysql_native_password'对用户'my_username'的主机'端点'进行身份验证失败。

$key = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000cb490db2b4c9fa44b669d5aef998b678000000000200000000001066000000010000200000003f506a26c5eeddc7620d8f9714d0ccc48968528840746270eba475f13b70a040000000000e80000000020000200000002d6f515408429f78324bc6b3589056810856bd4570fc61c717464e4f42ce691c2000000071d40064ee52a3222e3bcd64a8115d4ae1a3d6dd0daa64e7eab63fb72d5ce6d74000000034b9e0fe42c8fae724eb374a75e250da714372646099dfa076a2329673797ff3e13aedb1b79edcd2685f03802e40d7a43265fe16419acb238966298eda256567"
$password = ConvertTo-SecureString $key
[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$cn = New-Object -TypeName MySql.Data.MySqlClient.MySqlConnection
$cn.ConnectionString = "SERVER=$mysql_server;DATABASE=information_schema;UID=$mysql_user;PWD=$password"
$cn.Open()

0 个答案:

没有答案