当前位置:   article > 正文

Ubuntu下安装MongoDB_ubuntu安装mongodb tar

ubuntu安装mongodb tar

Ubuntu下安装MongoDB

转载自https://www.cnblogs.com/melonjiang/p/6536876.html

  • 下载python中MongoDB的驱动程序
   pip install pymongo
  • 1
  • 然后确保MongoDB已经安装且可以正常运行,去官网下载相应版本
mkdir -p /home/tools
cd/home/tools
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.2.tgz
  • 1
  • 2
  • 3
  • 解压文件并修改目录名
tar -zxvf mongodb-linux-x86_64-3.4.2.tgz
mv mongodb-linux-x86_64-3.4.2 mongodb3.4.2
ln -s mongodb_3.4.2 mongodb
  • 1
  • 2
  • 3
  • MongoDB 的可执行文件位于 bin 目录下,所以可以将其添加到 PATH 路径中
sudo vi ~/.profile
  • 1
export PATH=/home/tools/mongodb/bin:$PATH
  • 1
  • MongoDB的数据存储在data目录的db目录下,但是这个目录在安装过程不会自动创建,所以你需要手动创建data目录,并在data目录中创建db目录
mkdir -p /data/db
  • 1
  • 在mongo安装目录中的bin目录执行mongod命令来启动mongdb服务
./mongod --dbpath /data/db
  • 1
  • 如果想进入MongoDB后台管理
./mongo
  • 1
# ./mongo
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2
Welcome to the MongoDB shell.
.....................
times number of files.
2017-03-12T01:15:04.901+0800 I CONTROL  [initandlisten] 
> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 使用用户 admin 使用密码 123456 连接到本地的 MongoDB 服务上
> mongodb://admin:123456@localhost/
... 
  • 1
  • 2
  • 创建数据库(如果数据库不存在,则创建数据库,否则切换到指定数据库)
... use test
2017-03-12T01:34:04.361+0800 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):3:4
  • 1
  • 2
> use test
switched to db test
> db
test
> show dbs    #查看所有数据库
admin  0.000GB
local  0.000GB
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/891225
推荐阅读
相关标签
  

闽ICP备14008679号