连接: mongo 192.168.6.66:27017
登录 use admin db.auth("root","82xo#FR[G^oEME[iYU%ct~~N6LC(vWwC")
创建数据库 use project_admin_db db.test.insert({"id":"1"})
创建读写用户 db.createUser( { user:"customer", pwd:"q=%bJ~(+L3Mj8^Qoo2]Z6k5HRO!PhfHG", roles:[{role:"readWrite",db:"project_admin_db"}] } )
创建运维用户 db.createUser( { user:"dbAdmin", pwd:"L-$LpGQ=FJvSfGfHXN-)Z*RsFHI.$([l", roles:[{role:"dbAdmin",db:"project_admin_db"},{role:"readWrite",db:"project_admin_db"}] } )
cd C:\Program Files\MongoDB\Server\3.4\bin mongod.exe --logpath "E:\data\mongodb\log\mongodb.log" --logappend --dbpath "E:\data\mongodb\db" --serviceName "mongodb" --serviceDisplayName "mongodb" --auth --install 运行 services.msc 打开mongodb服务 打开目录 C:\Program Files\MongoDB\Server\3.4\bin 打开mongo.exe命令行 mongo use admin 创建超级管理员 db.createUser( { user:"root", pwd:"", roles:["root"] } ) db.auth('root','') use project_core_db 创建正式库读写用户 db.createUser( { user:"customer", pwd:"", roles:[{role:"readWrite",db:"project_core_db"}] } ) 创建正式库运维用户 db.createUser( { user:"dbAdmin", pwd:"", roles:[{role:"dbAdmin",db:"project_core_db"},{role:"readWrite",db:"project_core_db"}] } ) show users use project_core_db_test 创建测试库读写用户 db.createUser( { user:"customer", pwd:"", roles:[{role:"readWrite",db:"project_core_db_test"}] } ) 创建测试库运维用户 db.createUser( { user:"dbAdmin", pwd:"", roles:[{role:"dbAdmin",db:"project_core_db_test"},{role:"readWrite",db:"project_core_db_test"}] } ) 删除用户 db.dropUser('用户名') 备份 cd C:\Program Files\MongoDB\Server\3.4\bin 备份正式库 mongodump -h 106.5:27017 -d project_core_db -o E:\data\mongodb\backup -u dbAdmin -p H8 从测试库还原至正式库 mongorestore -h 106.5:27017 -d project_core_db --drop E:\data\mongodb\backup\project_core_db_test -u dbAdmin -p H8 从正式库还原至测试库 mongorestore -h 106.5:27017 -d project_core_db_test --drop E:\data\mongodb\backup\project_core_db -u dbAdmin -p H8 从正式库指定集合还原至测试库 mongorestore -c SysArea -h 106.5:27017 -d project_core_db_test --drop E:\data\mongodb\backup\project_core_db_test\SysArea.bson -u dbAdmin -p H8 备份测试库 mongodump -h 106.5:27017 -d project_core_db_test -o E:\data\mongodb\backup -u dbAdmin -p H8 从正式库还原至本地库 mongorestore -d project_core_db --drop D:\backup\db_backup\mongodb\project_core_db 从测试库还原至本地库 mongorestore -d project_core_db --drop D:\backup\db_backup\mongodb\project_core_db_test 备份本地库 mongodump -c SysArea -d project_core_db -o D:\backup\db_backup\mongodb\project_core_db 106.5:27017 正式库:project_core_db 测试库:project_core_db_test root H8