In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to solve the problem of MongoDB couldn't add user: not authorized on 'your db' to execute command". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to solve the problem of MongoDB couldn't add user: not authorized on 'your db' to execute command.
Solution: MongoDB couldn't add user: not authorized on 'your db' to execute command
I put a mongodb on the server two years ago, but now I have forgotten the authentication password and can't get in. Now record the recovery process.
1. Close the mongodb process first:
Method 1. / mongod-- shutdown-- dbpath / usr/local/mongo/data/db method 2. Kill process $ps-ef | grep mongo # list the processes of mongo 5451 5014 0 09:35 pts/11 00:00:00 / bin/sh / usr/local/mongodb/mongodb-linux-x86_64-ubuntu1604-3.2.8/bin/startmongodb.sh 5452 5451 1 09:35 pts/11 00:00:03. / mongod-- dbpath / usr/local/mongodb/mongodb-linux-x86_64-ubuntu1604-3.2.8/data/db 5539 5028 0 09:41 pts/12 00:00:00 grep-color=auto mongo$ kill 5452
two。 Modify the mongodb configuration file:
Vi / etc/mongodb.conf
find
Security:
Authorization, set the value to disabled
Security: authorization: disabled# authorization: enabled
3. Restart the database
Bring the database directory restart to work, otherwise the startup is an empty database, the previous data will not be found.
Now look at the disk usage on the server:
# du-ak / | sort-nrk 1 | head25818080 / 12535712 / var11605584 / var/lib6638668 / var/lib/docker6303520 / var/lib/docker/overlay24625676 / var/lib/mongodb4549080 / www3775880 / root3242504 / www/server3145744 / var/lib/mongodb/journal through my analysis / var/lib/mongodb this directory should be the database directory I previously set up # cd / var/lib/mongodb/ & ls-al [1] 7142total 1327156drwxr-xr-x 4 Mongodb mongodb 4096 Sep 8 15:56. Drwxr-xr-x 48 root root 4096 Dec 5 2019.-rw- 1 root root 67108864 Nov 7 2018 admin.0-rw- 1 root root 16777216 Nov 7 2018 admin.ns-rw- 1 root root 67108864 Nov 8 2018 aoWechat.0-rw- 1 root root 16777216 Nov 8 2018 aoWechat . ns-rw- 1 root root 67108864 Nov 6 2019 aoWeixin.0-rw- 1 root root 16777216 Oct 28 2019 aoWeixin.nsdrwxr-xr-x 2 root root 4096 Sep 8 16:12 diagnostic.datadrwxr-xr-x 2 mongodb mongodb 4096 Sep 8 16:07 journal-rw- 1 mongodb mongodb 67108864 Sep 8 16:07 local.0-rw- 1 mongodb mongodb 16777216 Sep 8 16:07 local.ns-rwxr-xr-x 1 mongodb mongodb 5 Sep 8 16:07 mongod.lock-rw- 1 root root 67108864 Oct 1 2019 chat.0-rw- 1 root root 134217728 Aug 20 2018 chat.1-rw- 1 root root 268435456 Oct 1 2019 chat.2-rw- 1 root root 536870912 Oct 1 2019 chat.3 -rw- 1 root root 16777216 Oct 1 2019 chat.ns-rw-r--r-- 1 root root 69 Aug 14 2018 storage.bson
The database directory has been found, now start the database with the directory
# mongod-- dbpath / var/lib/mongodb
This command only temporarily starts the database at the terminal, and then opens another terminal window to log in to the database.
#: mongo > > show dbsadmin 0.078GBaoWechat 0.078GBaoWeixin 0.078GBlocal 0.078GBsmart 0.953GB
Create a superuser:
Db.createUser ({user: "root", pwd: "123456", roles: [{role: "root", db: "admin"}]})
Exit the database, exit, and close the database.
Modify the configuration file to start authentication mode.
Vi / etc/mongod.conf
find
Security:
Authorization, set the value to enabled
Security: authorization: enabled
Now my complete configuration is as follows:
# mongod.conf# for documentation of all options, see:# http://docs.mongodb.org/manual/reference/configuration-options/# Where and how to store data.storage: dbPath: / var/lib/mongodb journal: enabled: truesystemLog: destination: file logAppend: true path: / var/log/mongodb/mongod.log# network interfacesnet: port: 27017 bindIp: 0.0.0.0security: authorization: enabled# authorization: disabled# authorization: enabledprocessManagement: fork: true
Officially start the database and restore is complete.
/ usr/bin/mongod-f / etc/mongod.conf
Go to the database and see if you can check the data.
# mongoMongoDB shell version: 3.2.20connecting to: test > use adminswitched to db admin > db.auth ('root','123456') 1 > show tablessystem.indexessystem.userssystem.version > show dbsadmin 0.078GBaohuoWechat 0.078GBaoshuoWeixin 0.078GBlocal 0.078GBsmartchat 0.953GB > at this point, I believe you have a better understanding of "how to solve the MongoDB couldn't add user: not authorized on' your db' to execute command problem". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.