duanjing1276 2014-11-13 17:00
浏览 204
已采纳

不允许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?

  • 写回答

1条回答 默认 最新

  • douyi7055 2014-11-13 17:07
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求Houdini使用行家,付费。价格面议。
  • ¥15 AttributeError: 'EasyDict' object has no attribute 'BACKUP_DB_INFO'
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。
  • ¥15 支付宝h5参数如何实现跳转
  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 CF1927D 求Hack