Mongodb維護基本命令
成都創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設,沁水企業(yè)網(wǎng)站建設,沁水品牌網(wǎng)站建設,網(wǎng)站定制,沁水網(wǎng)站建設報價,網(wǎng)絡營銷,網(wǎng)絡優(yōu)化,沁水網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。user管理命令適用在2.*版本3.*有些改動
1.查看詳細分片信息
mongos>sh.status()
---Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 4,
"minCompatibleVersion" : 4,
"currentVersion" : 5,
"clusterId" :ObjectId("569c8e920d9b1cb4bbf4169a")
}
shards:
{ "_id" : "shard1", "host" :"shard1/192.168.0.167:20200,192.168.0.25:20100" }
{ "_id" : "shard2", "host" :"shard2/192.168.0.167:20020,192.168.0.167:20030" }
{ "_id" : "shard3", "host" :"shard3/192.168.0.167:30003,192.168.0.25:30001" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : false, "primary" : "shard3" }
2.僅顯示分片
>useconfig;
>db.shards.find()
{"_id" : "shard1", "host" :"shard1/10.10.10.39:20100,10.10.10.49:20200" }
{"_id" : "shard2", "host" :"shard2/10.10.10.39:20010,10.10.10.49:20020" }
{"_id" : "shard3", "host" :"shard3/10.10.10.39:30001,10.10.10.49:30002" }
3.查看集群相關(guān)信息
mongos>db.serverStatus()
4.數(shù)據(jù)庫用戶及數(shù)據(jù)庫信息
mongos> show dbs;
admin 0.016GB
config 0.016GB
testdb 0.156GB
mongos> use ttdb \\創(chuàng)建數(shù)據(jù)庫
switched to db ttdb
mongos> db.addUser('tt','123456') \\為數(shù)據(jù)庫添加用戶名和密碼
WARNING: The 'addUser' shell helper isDEPRECATED. Please use 'createUser' instead
Successfully added user: { "user": "tt", "roles" : [ "dbOwner" ] }
# /mnt1/data/mongodbtest/mongodb/bin/mongo 192.168.0.25:20001/ttdb
MongoDB shell version: 2.6.5
connecting to: 192.168.0.25:20001/ttdb
mongos> show collections \\未使用用戶密碼登錄數(shù)據(jù)庫,報沒有權(quán)限錯誤
2016-01-18T17:42:27.981+0800 error: {
"$err": "not authorized for query on ttdb.system.namespaces",
"code": 13
} at src/mongo/shell/query.js:131
mongos> db \\查看當前所使用的數(shù)據(jù)庫
ttdb
mongos> db.auth('tt','123456')
1 \1代表驗證成功
mongos>show collections
mongos> use ttdb
switched to db ttdb
mongos> show collections
mongos> db.dropDatabase(); \\刪除數(shù)據(jù)庫
{ "dropped" : "ttdb","ok" : 1 }
mongos> use admin
switched to db admin
mongos> show dbs;
admin 0.016GB
config 0.016GB
mongos> use admin
mongos> db.system.users.find() \\查看當前數(shù)據(jù)庫的用戶
mongos> use ttdb
switched to db ttdb
mongos> db.dropUser("sa") \\刪除數(shù)據(jù)庫用戶
true
>use ttdb
>db.table1.stats(); \\查看表的狀態(tài)
db.addUser("tx","tx",ture); \\添加只讀的數(shù)據(jù)庫用戶
2016-01-26T16:16:26.153+0800ReferenceError: ture is not defined
mongos> db.addUser("tx","tx",true);
WARNING: The 'addUser' shell helper isDEPRECATED. Please use 'createUser' instead
Successfully added user: { "user": "tx", "roles" : [ "read" ] }
mongos>db.createCollection("Account")
{
"ok": 0,
"errmsg": "not authorized on ttdb to execute command { create:\"Account\" }",
"code": 13
} \\創(chuàng)建集合會報錯
5. balancer(復制相關(guān))
mongos> use config
switched to db config
mongos> sh.getBalancerState(); \\查看進程狀態(tài)
true
mongos> sh.stopBalancer();
Waiting for active hosts...
Waiting for the balancer lock...
Waiting again for active hosts afterbalancer is off...
mongos> sh.getBalancerState();
false
mongos> sh.startBalancer();
mongos> sh.getBalancerState();
true
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
新聞名稱:mongodb基本命令-創(chuàng)新互聯(lián)
文章URL:http://www.rwnh.cn/article16/cepigg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設、微信小程序、軟件開發(fā)、電子商務、網(wǎng)站營銷、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)