php远程连接MongoDB用户认证错误问题

来源:互联网 发布:网络命令的使用 编辑:程序博客网 时间:2024/06/07 06:26

php mongo扩展安装好了之后,本地调试没问题,结果远程连接别的电脑上mongodb数据库时候,始终出现问题

try{    $m = new MongoClient("10.100.0.159:27017");    $db = $m->smaap;    $db-> authenticate("xxxx","xxxx");}catch (Exception $e){    echo $e->getMessage();    exit();}

本机和需要连接的电脑在一个网段内,用户名和密码也没问题,结果老是弹出问题:

Failed to connect to: 10.100.0.159:27017: Authentication failed on database ‘xxxx’ with username ‘xxxx’: auth failed

各种调试,各种搜索,貌似别人都没有出现这个问题啊,百思不得其解。最后终于搜到了这篇文章,http://blog.csdn.net/zz87541368/article/details/45023895


结果phpinfo()也是出现了这篇文章的现象。

上mongo的官方文档中查找一番,关于mongodb的认证机制:

MongoDB’s default authentication method is a challenge and response mechanism (SCRAM-SHA-1). Previously, MongoDB used MongoDB Challenge and Response (MONGODB-CR) as the default.

mongo3.0之后就不使用MONGO-CR作为默认的用户认证方式了,默认的是SCRAM-SHA-1

赶快到phpinfo mongo部分看到:

Supported Authentication Mechanisms-MONGODB-CR (default)enabledMONGODB-X509enabledGSSAPI(Kerberos)enabledPLAINenabled

  
没有SCRAM-SHA-1

https://pecl.php.net/package/mongo里搜最新的,且符合自己电脑版本对应的驱动装上,调试一下就可以了。


原创粉丝点击