不允许Perl / MySQL'主机'和'失败:客户端不支持服务器请求的身份验证协议'错误?
I am writing a Perl script that is being executed from a remote UNIX server. The script is supposed to connect to my localhost machine, and post some data to the MySQL server running by XAMPP. I used the following code to initiate a connection:
my $dbHost = "my-machine-name";
my $dbUsername = "root";
my $dbPassword = "";
my $databaseName = "myDB";
my $connection = DBI->connect("DBI:mysql:$databaseName;host=$dbHost",
$dbUsername, $dbPassword, { RaiseError => 1 } )
or die ( "Couldn't connect to database: " . DBI->errstr );
At first I was getting:
Host ... is not allowed to connect to this MySQL server
Then I read that I need to add the rejected host to the list of users. So I opened XAMPP Control, clicked on XAMPP->ADMIN to open phpMyAdmin, then navigated to the user table, copied the row that said host=127.0.0.1 and then modified the 127.0.0.1 to the rejected IP I was getting. Then I opened XAMPP Control again, stopped both Apache and MySQL, and then started them.
Now, I am getting:
DBI connect('myDB;host=my-machine-name','root',...) failed: Client does not support authentication protocol requested by server; consider upgrading MySQL client at ...
I tried changing the hostname from the string-name to the IPv4 Address, and still got the same error. Also tried adding the :3306
to the end of the host, but got the same error.
Any idea what I can do to access a localhosted MySQL from a remote server?
我正在编写一个从远程UNIX服务器执行的Perl脚本。 该脚本应该连接到我的localhost机器,并将一些数据发布到由XAMPP运行的MySQL服务器上。 我使用以下代码启动连接: p>
my $ dbHost =“my-machine-name”;
$ dbUsername =“root”;
my $ dbPassword =“”;
my $ databaseName =“myDB”;
my $ connection = DBI-> connect(“DBI:mysql:$ databaseName; host = $ dbHost”,
$ dbUsername,$ dbPassword,{RaiseError =&gt ; 1})
或死(“无法连接到数据库:”。DBI-> errstr);
code> pre>
起初我得到:
主机...不允许连接到此MySQL服务器 p>
blockquote>
然后我读取我需要将被拒绝的主机添加到用户列表中 。 所以我打开了XAMPP Control,点击了XAMPP-> ADMIN打开phpMyAdmin,然后导航到用户表,复制了表示host = 127.0.0.1的行,然后将127.0.0.1修改为我得到的被拒绝的IP。 然后我再次打开XAMPP Control,停止Apache和MySQL,然后启动它们。 p>
现在,我得到了: p>
DBI connect('myDB; host = my-machine-name','root ',...)
失败:客户端不支持
服务器请求的身份验证协议; 考虑升级MySQL客户端... p>
blockquote>
我尝试将主机名从字符串名称更改为IPv4地址,但仍然遇到相同的错误。 还尝试将:3306 code>添加到主机的末尾,但得到了同样的错误。 p>
知道如何从远程服务器访问本地主机的MySQL? p>
div>
This should work:
$server = 'your server';
$port = '3306';
$user = 'your_user';
$pass = 'your_pass';
$database = 'database';
$dbConn = DBI->connect("DBI:mysql:$database:$server:$port", "$user", "$pass")
or die "Couldn't connect to database: " . DBI->errstr;