停库

db.shutdownServer()

备份

nohup /opt/software/mongodb/mongodb-linux-x86_64-rhel70-4.2.9/bin/mongodump -h mongodb-hub-service0001:27017 --authenticationDatabase=admin -u root -p密码 -o /dataMongoDB/backup_mongodb_full/mongodb-hub-service0001_27017 &

执行JavaScript脚本

./mongo mongodb://ip:27018,ip:27019,ip:27017/库名 /tmp/mongo.js

用户管理

切换MongoDB的库
use admin

验证用户名与密码
db.auth('username','password')

查询所有的用户
db.system.users.find().pretty()

查询当前库下的用户
show users

创建用户
-- 管理员
db.createUser({user:"root",pwd:"xxxx",roles:[{role:"root",db:"admin"},{role:"dbAdminAnyDatabase",db:"admin"},{role:"clusterAdmin",db:"admin"}]})

db.createUser({user:"root",pwd:"xxx",roles:[{role:"root",db:"admin"}]})

-- 普通用户
db.createUser({user:"username",pwd:"password",roles:[{role:"readWrite",db:"db_name"}]})

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

隐藏
变装