mongodb (一)
#mongodb安装(3.4.0)
#下载安装包,解压
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 #添加管理员后取消注释,重启开启验证模式,不注释,启动时加—noauth
#bin目录,把解压包bin目录下的所有文件复制到安装目录的bin下
./mongod –f /data/mongodb/conf/mongod.conf
#参数
-f 配置文件
….
#登录
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, "salt" : "1TGN5bEPBecuWXrna91t7g==", "storedKey" : "S8ABUikXg21EHmMNBhbh+JUjld4=", "serverKey" : "RLrv3SUUODtOqV3p0df5fUwNpNQ=" } }, "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] }
#验证
db.auth(“root”,”root”)
#db名
>db
admin
> db.getName()
admin