Mongodb与mysql语法比较

来源:未知 责任编辑:责任编辑 发表时间:2014-04-20 03:42 点击:
Mongodb与mysql语法比较
 
mongodb与mysql命令对比
传统的关系数据库一般由数据库(database)、表(table)、记录(record)三个层次概念组成,MongoDB是由数据库(database)、集合(collection)、文档对象(document)三个层次组成。MongoDB对于关系型数据库里的表,但是集合中没有列、行和关系概念,这体现了模式自由的特点。 
MySQL
MongoDB
说明
mysqld
mongod
服务器守护进程
mysql
mongo
客户端工具
mysqldump
mongodump
逻辑备份工具
mysql
mongorestore
逻辑恢复工具
   www.2cto.com  
db.repairDatabase()
修复数据库
mysqldump
mongoexport
数据导出工具
source
mongoimport
数据导入工具
grant * privileges on *.* to …
Db.addUser()
Db.auth()
新建用户并权限
show databases
show dbs
显示库列表
Show tables
Show collections
显示表列表
Show slave status
Rs.status
查询主从状态
Create table users(a int, b int)
db.createCollection("mycoll", {capped:true,
size:100000}) 另:可隐式创建表。
创建表
Create INDEX idxname ON users(name)
db.users.ensureIndex({name:1})
创建索引
Create INDEX idxname ON users(name,ts DESC)
db.users.ensureIndex({name:1,ts:-1})
创建索引
Insert into users values(1, 1)
db.users.insert({a:1, b:1})
插入记录
Select a, b from users
db.users.find({},{a:1, b:1})
查询表
Select * from users
db.users.find()
查询表
Select * from users where age=33
db.users.find({age:33})
条件查询  www.2cto.com  
Select a, b from users where age=33
db.users.find({age:33},{a:1, b:1})
条件查询
select * from users where age<33
db.users.find({'age':{$lt:33}})
条件查询
select * from users where age>33 and age<=40
db.users.find({'age':{$gt:33,$lte:40}})
条件查询
select * from users where a=1 and b='q'
db.users.find({a:1,b:'q'})
条件查询
select * from users where a=1 or b=2
db.users.find( { $or : [ { a : 1 } , { b : 2 } ] } )
条件查询
select * from users limit 1
db.users.findOne()
条件查询
select * from users where name like "%Joe%"
db.users.find({name:/Joe/})
模糊查询
select * from users where name like "Joe%"
db.users.find({name:/^Joe/})
模糊查询
select count(1) from users
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Request.ServerVariables 参数大全
  • 执行全文索引时出现权限不足的解决方法
  • 导入excel文件处理流程节点的解决方案
  • 查看sql修改痕迹(SQL Change Tracking on Table)
  • App数据层设计及云存储使用指南
  • PostgreSQL启动过程中的那些事三:加载GUC参数
  • MongoDB安装为Windows服务方法与注意事项
  • Percolator与分布式事务思考(二)
  • 写给MongoDB开发者的50条建议Tip1
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1