刘勇虎的官方网站
网站内容包含大前端、服务器开发、Python开发、iOS开发、Android开发、网站维护等技术文章。专注于分享技术经验,职业心得体会,IT优秀文章与教程创作。
Stay hungry,Stay foolish,Stay young
题记
今天给服务器的mongodb数据库数据备份的时候发现了个错误 -
Failed: error getting database names: command listDatabases requires authentication
,百度了一下也没搞到好的解决办法,最后自己研究了一下,发现了还是自己不太清楚 mongo 的指令,最后解决了。
命令行运行:
mongodump
报错信息:
[root@VM_0_6_centos ~]# mongodump
2020-02-29T16:56:52.186+0800 Failed: error getting database names: command listDatabases requires authentication
搜索的过程就不再赘述,直接上解决的过程
命令行输入求助:
mongodump --help
打印信息:
Usage:
mongodump <options>
Export the content of a running server into .bson files.
Specify a database with -d and a collection with -c to only dump that database or collection.
See http://docs.mongodb.org/manual/reference/program/mongodump/ for more information.
general options:
--help print usage
--version print the tool version and exit
verbosity options:
-v, --verbose=<level> more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or
specify a numeric value, e.g. --verbose=N)
--quiet hide all log output
connection options:
-h, --host=<hostname> mongodb host to connect to (setname/host1,host2 for replica sets)
--port=<port> server port (can also use --host hostname:port)
authentication options:
-u, --username=<username> username for authentication
-p, --password=<password> password for authentication
--authenticationDatabase=<database-name> database that holds the user's credentials
--authenticationMechanism=<mechanism> authentication mechanism to use
namespace options:
-d, --db=<database-name> database to use
-c, --collection=<collection-name> collection to use
uri options:
--uri=mongodb-uri mongodb uri connection string
query options:
-q, --query= query filter, as a JSON string, e.g., '{x:{$gt:1}}'
--queryFile= path to a file containing a query filter (JSON)
--readPreference=<string>|<json> specify either a preference name or a preference json object
--forceTableScan force a table scan
output options:
-o, --out=<directory-path> output directory, or '-' for stdout (defaults to 'dump')
--gzip compress archive our collection output with Gzip
--repair try to recover documents from damaged data files (not supported by all storage engines)
--oplog use oplog for taking a point-in-time snapshot
--archive=<file-path> dump as an archive to the specified path. If flag is specified without a value, archive
is written to stdout
--dumpDbUsersAndRoles dump user and role definitions for the specified database
--excludeCollection=<collection-name> collection to exclude from the dump (may be specified multiple times to exclude
additional collections)
--excludeCollectionsWithPrefix=<collection-prefix> exclude all collections from the dump that have the given prefix (may be specified
multiple times to exclude additional prefixes)
-j, --numParallelCollections= number of collections to dump in parallel (4 by default) (default: 4)
--viewsAsCollections dump views as normal collections with their produced data, omitting standard collections
其中有提示:
authentication options:
-u, --username=<username> username for authentication
-p, --password=<password> password for authentication
那么就输入指令
mongodump --username=<username> --password=<password>
完美解决
2020-02-29T17:00:32.953+0800 writing admin.system.
2020-02-29T17:00:32.975+0800 done dumping admin.
2020-02-29T17:00:32.975+0800 writing admin.system.
2020-02-29T17:00:32.997+0800 done dumping admin.
2020-02-29T17:00:32.997+0800 writing tdata.
2020-02-29T17:00:32.997+0800 writing ***
2020-02-29T17:00:32.997+0800 writing ***
2020-02-29T17:00:32.997+0800 writing ***
2020-02-29T17:00:33.098+0800 done ***
2020-02-29T17:00:33.098+0800 writing ***
2020-02-29T17:00:33.098+0800 done dumping ***
2020-02-29T17:00:33.098+0800 writing ***
2020-02-29T17:00:33.099+0800 done ***
2020-02-29T17:00:33.099+0800 writing ***
2020-02-29T17:00:33.100+0800 done dumping ***
2020-02-29T17:00:33.163+0800 done dumping ***
2020-02-29T17:00:33.163+0800 done dumping ***
2020-02-29T17:00:33.169+0800 done dumping ***