温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

DBA应用技巧中如何利用MySQL技能学习MongoDB

发布时间:2021-09-29 10:35:03 来源:亿速云 阅读:142 作者:柒染 栏目:数据库

DBA应用技巧中如何利用MySQL技能学习MongoDB,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

(1)、mongorestore恢复工具  我们先看一下此工具的帮助信息:

双击代码全选
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24[root@localhost bin]# ./mongorestore --helpusage: ./mongorestore [options] [directory or filename to restore from]options:   --help                  produce help message   -v [ --verbose ]        be more verbose (include multiple times for more                           verbosity e.g. -vvvvv)   -h [ --host ] arg       mongo host to connect to ( <set name>/s1,s2 for sets)   --port arg              server port. Can also use --host hostname:port   --ipv6                  enable IPv6 support (disabled by default)   -u [ --username ] arg   username   -p [ --password ] arg   password   --dbpath arg            directly access mongod database files in the given                           path, instead of connecting to a mongod  server -                           needs to lock the data directory, so cannot be used                           if a mongod is currently accessing the same path   --directoryperdb        if dbpath specified, each db is in a separate                           directory   -d [ --db ] arg         database to use   -c [ --collection ] arg collection to use (some commands)   --objcheck              validate object before inserting   --filter arg            filter to apply before inserting   --drop                  drop each collection before import   --oplogReplay           replay oplog for point-in-time restore[root@localhost bin]#

  例如我们先将”foo”库删除了:

双击代码全选
1 2 3 4 5 6 7 8 9 10 11 12[root@localhost bin]# ./mongoMongoDB shell version: 1.8.1connecting to: test> use fooswitched to db foo> db.dropDatabase();{ "dropped" : "foo", "ok" : 1 }> show dbsadmin   0.0625GBlocal   (empty)test    0.0625GB>

  然后下面我们将演示如何恢复这个库:

双击代码全选
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18[root@localhost bin]# ./mongorestore --directoryperdb /data/dumpconnected to: 127.0.0.1Sun Apr 22 12:01:27 /data/dump/foo/t1.bsonSun Apr 22 12:01:27      going into namespace [foo.t1]Sun Apr 22 12:01:27      2 objects foundSun Apr 22 12:01:27 /data/dump/foo/t2.bsonSun Apr 22 12:01:27      going into namespace [foo.t2]Sun Apr 22 12:01:27      1 objects foundSun Apr 22 12:01:27 /data/dump/foo/system.users.bsonSun Apr 22 12:01:27      going into namespace [foo.system.users]Sun Apr 22 12:01:27      1 objects foundSun Apr 22 12:01:27 /data/dump/foo/system.indexes.bsonSun Apr 22 12:01:27      going into namespace [foo.system.indexes]Sun Apr 22 12:01:27 { name: "_id_", ns: "foo.system.users", key: { _id: 1 }, v: 0 }Sun Apr 22 12:01:27 { name: "_id_", ns: "foo.t2", key: { _id: 1 }, v: 0 }Sun Apr 22 12:01:27 { name: "_id_", ns: "foo.t1", key: { _id: 1 }, v: 0 }Sun Apr 22 12:01:27      3 objects found[root@localhost bin]#

  通过工具返回信息,我们可以看到foo中的数据已经被恢复回来了, 接下来我们到库里去验证一下:

双击代码全选
1 2 3 4 5 6 7 8 9 10 11[root@localhost bin]# ./mongoMongoDB shell version: 1.8.1connecting to: test> use fooswitched to db foo> show collections;system.indexessystem.userst1t2>

  结果证明foo库表已经被成功恢复回来了。

关于DBA应用技巧中如何利用MySQL技能学习MongoDB问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI