1. Service Start-up
- After downloading the installation steps, please see the MongoDB installation detailed tutorial
- Start the service
NET START MongoDB
- Close Service
NET STOP MongoDB
- Start the client MONGO
- MongoDB Shell version v3.6.0
- Connecting to:mongodb://127.0.0.1:27017
- MongoDB Server version:3.6.0
2. Set password and user rights 2.1 turn on security verification
- Mode one: At the command line input
mongod --auth --logpath "D:\Program Files\mongodb\data\log\MongoDB.log" --logappend --dbpath "D:\Program Files\mongodb\data\db" --directoryperdb --reinstall
- Mode two: input at the command line
mongod --dbpath "G:\mongoDB\data\db" --logpath "G:\mongoDB\data\log\MongoDB.log" --auth
2.2 Creating a user
- Navigate to D:\Program Files \mongodb\bin and use Mongo.exe to enter MongoDB's command line management.
- Type the following command
>use admin
>db.createUser({user:"yangjing",pwd:"123456",roles:["userAdminAnyDatabase"]})
- Now we add a user root for the MongoDB Admin database, and the password is ROOT,MONGODB can establish permission authentication for each database, that is, you can specify which database a user can log into. The above code, we added a root user for the admin database, in MongoDB, the admin database is a special database, the user of this database can access all the databases in MongoDB.
If you want to set up a user for the test database, use the following command
>use test
>db.createUser({user:"yangjing",pwd:"123456"})
OK, now that we've set up a global user root for MongoDB, we'll restart MongoDB to make the created user effective.
2.3 User Login
- The first thing you need to do is jump to the current database mode using the "Use database name, such as: Usage admin", then log in
下面1表示登录成功,0表示登录失败。
db.auth("yangjing","123456")
MongoDB Startup and user name password settings