美文网首页数据
4、PHP测试分片集群

4、PHP测试分片集群

作者: Uzero | 来源:发表于2017-04-07 14:22 被阅读11次

对数据库test_db2新建两个用户,一个只读用户,一个读写用户

user test_db2

#可读可写

db.createUser(

       {

               user:"ybl",

               pwd:"6055",

               roles:[{"role":"readWrite","db":"test_db2"}]

        }

)

#只读

db.createUser(

       {

               user:"xjl",

               pwd:"6055",

               roles:[{"role":"read","db":"test_db2"}]

       }

)

php安装MongoDB扩展查看此处

<?php

try{    $conn=new\MongoClient("mongodb://ybl:6055@127.0.0.143:20000,127.0.0.144:20000",array("db"=>"test_db2"));

}catch(MongoConnectionException$e){

       echo$e->getMessage();

}

如果认证未通过,则捕获到异常

Failed to connect to: 10.99.121.185:20000: SASL

Authentication failed on database 'test_db': Authentication failed.; Failed to

connect to: ybl:6055@10.99.121.187:20000: php_network_getaddresses: getaddrinfo

failed: Name or service not known12

相关文章

网友评论

    本文标题:4、PHP测试分片集群

    本文链接:https://www.haomeiwen.com/subject/wojhattx.html