溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

DBA應(yīng)用技巧中如何利用MySQL技能學(xué)習(xí)MongoDB

發(fā)布時間:2021-09-29 10:35:03 來源:億速云 閱讀:153 作者:柒染 欄目:數(shù)據(jù)庫

DBA應(yīng)用技巧中如何利用MySQL技能學(xué)習(xí)MongoDB,針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

(1)、mongorestore恢復(fù)工具  我們先看一下此工具的幫助信息:

雙擊代碼全選
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>

  然后下面我們將演示如何恢復(fù)這個庫:

雙擊代碼全選
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中的數(shù)據(jù)已經(jīng)被恢復(fù)回來了, 接下來我們到庫里去驗證一下:

雙擊代碼全選
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>

  結(jié)果證明foo庫表已經(jīng)被成功恢復(fù)回來了。

關(guān)于DBA應(yīng)用技巧中如何利用MySQL技能學(xué)習(xí)MongoDB問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI