Skip to content

1、 查看数据库

>mongo

>show dbs;
admin    0.000GB
config   0.000GB
local    0.000GB

在命令行工具中 输入 mongo 回车 就可以输入 mongo 命令

show dbs 是查看当前 有哪些数据库

2、初始化数据库


>use comment
switched to db comment

use comment 意思是 使用 comment 这个数据库

如果没有,就会 新创建 1 个

3、初始化 用户

为当前 数据库 创建 1 个 只有 当前数据库的 权限的 用户

>db.createUser({
    user:"wugs_comment",
    pwd:"123456",
    roles:[{
        role:"readWrite",
        db:"comment"
    }]
})

Successfully added user: {
	"user" : "wugs_comment",
	"roles" : [
		{
			"role" : "readWrite",
			"db" : "comment"
		}
	]
}

成功创建了 一个 用户名为 wugs_comment 的用户, 拥有 数据库 comment 的读写权限

4、端口不是 默认的 27017

mongo --port 10001