Home > Database > Mysql Tutorial > body text

mongoDB第六讲

WBOY
Release: 2016-06-07 15:54:41
Original
1026 people have browsed it

?mongoDB启动配置详解 1.启动项 mongod --help 1.1利用config配置文件来启动数据库改变端口为8888 mongodb.conf文件 dbpath = D:\app\mongodata port = 8888 启动文件 mongod.exe --config mongodb.conf shell文件 mongo 127.0.0.1:8888 2.停止mongoDB服务 1

?mongoDB启动配置详解

1.启动项 mongod --help

\

1.1利用config配置文件来启动数据库改变端口为8888

mongodb.conf文件

dbpath = D:\app\mongodata

port = 8888

启动文件

mongod.exe --config mongodb.conf

shell文件

mongo 127.0.0.1:8888

2.停止mongoDB服务

1.1ctrl+c 组合键可以关闭数据库

1.2admin数据库命令关闭数据

use admin

db.shutdownServer()

?导出,导入,运行时备份 一导出、导入

1.导出数据(中断其他操作)

打开CMD

利用mongoexport

-d 指明使用的库

-c 指明要导出的表

-o 指明要导出的文件名

-csv 制定导出的csv格式

-q 过滤导出

--type

1.1把数据好foobar中的persons导出

mongoexport -d foobar -c persons -oD:/persons.json

1.2导出其他主机数据库的文档

mongoexport --host 192.168.0.16 --port 37017

2.导入数据(中断其他操作)

2.1到入persons文件

mongoimport --db foobar --collection persons --file d:/persons.json

二备份

1.运行时备份mongodump

1.1导出127.0.0.1服务下的27017下的foobar数据库

mongodump --host 127.0.0.1:27017 -d foobar -o d:/foobar

2.运行时恢复mongorestore

2.1删除原本的数据库用刚才导出的数据库恢复

db.dropDatabase()

mongorestore --host 127.0.0.1:27017 -d foobar -directoryperdb d:/foobar/foobar

3.懒人备份

mongoDB是文件数据库这其实就可以用拷贝文件的方式进行备份

?Fsync锁,数据修复

1.Fsync的使用

先来看看mongoDB的简单结构

\

2.上锁和解锁

上锁

db.runCommand({fsync:1,lock:1});

解锁

db.currentOp()

3.数据修复

当停电等不可逆转灾难来临的时候,由于mongodb的存储结构导致

会产生垃圾数据,在数据恢复以后这垃圾数据依然存在,这是数据库

提供一个自我修复的能力.使用起来很简单

db.repairDatabase()

?用户管理,安全认证 http://www.cnblogs.com/dennisit/archive/2013/02/22/2922906.html

1.添加一个用户

1.1为admin添加uspcat用户和foobar数据库的zhang用户

use admin

db.addUser(“uspcat”,”123”);

use foobar

db.addUser(“zhang”,”123”);

2.启用用户

db.auth(“名称”,”密码”)

3.安全检查 --auth

mogod --dbpath d:\app\mongodata --auth

mogo localhost:27017

use foobar

db.persons.find() //会报错

非foobar的用户是不能操作数据库的,启用自己的用户才能访问

db.auth("zhang","123")

非admin数据库的用户不能使用数据库命令

db.auth("zhang","123")

show dbs //会报错

admin数据库中的数据经过认证为管理员用户

4.用户删除操作

db.system.users.remove({user:"zhang"});

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!