1,创建mongodb.repo文件
在/etc/yum.repos.d/目录下创建文件mongodb.repo,它包含MongoDB仓库的配置信息,内容如下:
[mongodb] name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
2,执行安装命令
# yum clean all
# yum list | grep mongo
# yum -y install mongodb-org
# rpm -qa |grep mongodb
查看mongo占用的端口(默认27017)
# ss -anp |grep mongod
3. 创建超级管理员账户相关操作
db.createUser({
“user” : “root”,
“pwd” : “123456”,
“roles” : [
{role: “userAdminAnyDatabase”, db: “admin”},
{role: “dbAdminAnyDatabase”, db: “admin” },
{role: “readWriteAnyDatabase”, db: “admin” }
] })
show dbs
use admin
db.createUser({“user” : “root”, “pwd” : “123456”, “roles” : [{role: “userAdminAnyDatabase”, db: “admin”}, {role: “dbAdminAnyDatabase”, db: “admin” }, {role: “readWriteAnyDatabase”, db: “admin” }]})
db.updateUser(“root”,{roles : [{“role” : “__system”,”db” : “admin”},{“role” : “root”, “db”: “admin”}]})
show roles
db.shutdownServer()
db.auth(‘root’, ‘123456’)
db.system.users.find()
db.system.users.remove({user:”admin”})
4.mongo的启动和关闭
/usr/bin/mongod -auth -f /etc/mongod.conf
mongo admin -uroot -p
service mongod stop
db.shutdownServer()
修改用户密码 : db.changeUserPassword(‘tank2′,’test’);
5. 管理软件
phpMongoAdmin(php)
https://github.com/CraryPrimitiveMan/phpMongoAdmin
rockmongo(php)
http://rockmongo.com/
Robomongo (GUI)
http://robomongo.org/
mongobooster (GUI)
http://mongobooster.org /
6.创建数据库, 创建集合(表),创建文档(字段)
db.testdb
db.createCollection(“name”, { capped : true, size : 512 * 1024, max : 1000 } )
show collections
db.word.save({‘word’:”, ‘explain’:”, ‘sound’: ”, ‘movie’:”, ‘movie_cover_img’:”, ‘img’:”, ‘status’:”, ‘property’:0, ‘remember’:”, ‘extension’:{}})
db.ChoiceQuestion.save({‘title’:{}, ‘answers’:[], ‘options’: [], ‘need_sound’: 0, ‘type’: 0, ‘status’:0})
db.Word.find({})
参考:
http://www.tuicool.com/articles/fMZbUzu
https://segmentfault.com/q/1010000002923686
http://www.xuejiehome.com/blread-1444.html
http://www.cnblogs.com/lindsay-chh/p/4734568.html
http://blog.csdn.net/xht555/article/details/40918951
原文链接:https://www.hertzdance.com/blog/centos-6-5-yum-mongodb-2-6,转载请注明出处。
评论0