mongDB创建新的数据库(带密码)

1、 cd /www/server/mongodb/bin

2、进入mongo终端    ./mongo

3、效验root权限  

 (1): use admin 
 (2):db.auth("root","he449231013")

4、创建新的数据库 

       use Article

5、创建新数据库的账户密码

      db.createUser({user:'test',pwd:'123456',roles: [{role:'readWrite',db:'Article'}]})

6、给数据库增加数据(目的 不让数据库因为没有数据自动删除)

  db.runoob.insert({"name":"菜鸟教程"})

创建 root 帐号

db.createUser({user: 'root', pwd: 'xxxxxxxxxxx', roles: ['root']})

27017端口连接不上。

mongodb的配置文件中的bind_ip 默认为127.0.0.1,默认只有本机可以连接。  此时,需要将bind_ip配置为0.0.0.0,表示接受任何IP的连接。

posted @ 2021-09-02 14:59  我改网名了  阅读(216)  评论(0)    收藏  举报