作用 | | |
| | |
服务器守护进程 | | |
客户端工具 | | |
逻辑备份工具 | | |
逻辑还原工具 | | |
数据导出工具 | | |
数据导入工具 | | |
| | |
新建用户并授权 | grant all on *.* to username@'localhost' identified by 'passwd'; | db.addUser("user","psw") db.auth("user","psw") |
显示库列表 | | |
进去库 | | |
显示表列表 | | |
查询主从状态 | | |
创建库 | | |
创建表 | create table tname(id int); | |
删除表 | | |
删除库 | | |
| | |
插入记录 | insert into tname(id) value(2); | |
删除记录 | delete from tname where id=2; | |
修改/更新记录 | update tname set id=3 where id=2; | db.tname.update({id:2}, {$set:{id:3}},false,true) |
| | |
查询所有记录 | | |
查询所有列 | | |
条件查询 | select * from tname where id=2; | |
条件查询 | select * from tname where id < 2; | db.tname.find({id:{$lt:2}}) |
条件查询 | select * from tname where id >=2; | db.tname.find({id:{$gte:2}}) |
条件查询 | select * from tname where id=2 and name='steve'; | db.tname.find({id:2, name:'steve'}) |
条件查询 | select * from tname where id=2 or name='steve'; | db.tname.find($or:[{id:2}, {name:'steve'}]) |
条件查询 | select * from tname limit 1; | |
| | |
模糊查询 | select * from tname where name like "%ste%"; | db.tname.find({name:/ste/}) |
模糊查询 | select * from tname where name like "ste%"; | db.tname.find({name:/^ste/}) |
| | |
获取表记录数 | select count(id) from tname; | |
获取有条件 的记录数 | select count(id) from tname where id=2; | db.tname.find({id:2}).count() |
查询时去掉 重复值 | select distinct(last_name) from tname; | db.tname.distinct('last_name') |
| | |
正排序查询 | select *from tname order by id; | db.tname.find().sort({id:1}) |
逆排序查询 | select *from tname order by id desc; | db.tname.find().sort({id:-1}) |
| | |
取存储路径 | explain select * from tname where id=3; | db.tname.find({id=3}).explain() |