#mongodb安装 (3.4.0)
#下载安装包, unzip
Mkdir/data/mongodb
Cd/data/mongodb
mkdir Log conf Data bin
Vim conf/mongod.conf
#添加一下内容
port=27017
Dbpath=/data/mongodb/data
Logpath=/data/mongodb/log/mongod.log
Fork=true
#auth =true #添加管理员后取消注释, restart the authentication mode, do not comment, start adding-noauth
#bin目录, copy all files from the unpacking bin directory to the bin of the installation directory
./mongod–f/data/mongodb/conf/mongod.conf
#参数
-F configuration file
....
#登录
Mongo
Use admin
#创建管理员账户
Db.createuser ({User: "root", pwd: "Root", Roles:[{role: "Useradminanydatabase", DB: "Admin"}]})
#查看账户
> Show Users;
{
"_id": "Admin.root",
"User": "Root",
"DB": "admin",
"Roles": [
{
"Role": "Useradminanydatabase",
"DB": "admin"
}
]
}
> Db.system.users.find ()
{"_id": "Admin.root", "User": "Root", "db": "admin", "credentials": {"Scram-sha-1": {"IterationCount": 10000, "SA LT ":" 1tgn5bepbecuwxrna91t7g== "," Storedkey ":" s8abuikxg21ehmmnbhbh+jujld4= "," Serverkey ":" Rlrv3suuodtoqv3p0df5fuwnpnq= "}}," Roles ": [{" Role ":" Useradminanydatabase "," db ":" Admin "}]}
#验证
Db.auth ("root", "root")
#db名
>db
Admin
> Db.getname ()
Admin
MongoDB (i)