記Ubuntu Mongodb 和 Mysql的安裝與使用

安裝mongodb

參考連接html

http://www.javashuo.com/article/p-efnbmhzq-dp.htmlmysql

https://blog.csdn.net/xlengji/article/details/81052151sql

Ubuntu16.04安裝mongodbmongodb

sudo apt-get install mongodb
mongo -version # 查看MongoDB版本

# 啓動和關閉mongodb命令
service mongodb start
service mongodb stop

# 默認設置MongoDB是隨Ubuntu啓動自動啓動的。 輸入如下命令查看是否啓動成功:
pgrep mongo -l

 

建立帳戶密碼(未試)

修改/etc/mongodb.conf文件, 將auth=true前面的#號去掉,開啓動用戶權限認證shell

進入mongo,添加帳號密碼數據庫

use admin  //用admin身份  ubuntu

db.createUser({user:"guoke",pwd:"55",roles:["root"]})//建立帳號  vim

db.auth("guoke","55")//就能夠進入了 socket

 

建立帳號以後,若是沒有登陸而使用,則會報錯,只有先登陸後才能夠使用ionic

 

ubuntu16.04經過apt-get方式安裝MongoDB 最新版

ubuntu16.04經過apt-get方式安裝MongoDB 

Ubuntu 16.04 LTS 安裝Mongodb 3.4

官網:https://www.mongodb.com/download-center/community

官網教程:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

雖然Ubuntu自己也提供MongoDB安裝包,但每每官網的安裝包版本更新

 

 1.導入包管理系統使用的公鑰

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

2.爲MongoDB建立一個列表文件

根據版本建立/etc/apt/sources.list.d/mongodb-org-3.4.list 列表文件

Ubuntu14.04:

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Ubuntu16.04:

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

Ubuntu18.04:

echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list

3.更新本地包數據庫

sudo apt-get update

4.安裝最新版本的MongoDB

sudo apt-get install -y mongodb-org

或者安裝特定版本的 MongoDB(必須單獨指定每一個組件包以及版本號)

sudo apt-get install -y mongodb-org=4.0.6 mongodb-org-server=4.0.6 mongodb-org-shell=4.0.6 mongodb-org-mongos=4.0.6 mongodb-org-tools=4.0.6

 

 

 問題:

Failed to start mongodb.service: Unit mongodb.service is masked.

解決方案:

參考連接:http://club.verimake.com/topics/36

The latest version of MongoDB does most of needs except one thing for now. After installing MongoDB on Ubuntu 16.04.x then run the commands as follows:
First create mongodb.service file by follow command :(只能用vim,gedit打不開這個文件)

sudo vim /etc/systemd/system/mongodb.service

將下面內容粘貼進mongodb.service,而後使用wq退出vim

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

Then , run these commands on the terminal one by one:

sudo systemctl enable mongod.service

sudo systemctl daemon-reload

sudo service mongod start

 

 

  

安裝Studio3T圖形界面

https://studio3t.com/download/

下載直接next安裝便可

進去以後 新建Connect -- 新建數據庫 -- 新建Collections

 

mongodb IntelliShell

db.getCollection("h6vmovie").find({'page_url':'http://www.hao6v.com/dy/2018-04-23/MouShaQiong.html'})

db.h6vmovie.getIndexes()
db.h6vmovie.dropIndex("name_1_year_1")
db.h6vmovie.dropIndex("name.local_1_name.str_1_year_1")

db.h6vmovie.createIndex({'name.local':1, 'name.str':1, year:1},{unique:true})
db.h6vmovie.createIndex({name:1, year:1, page_url:1},{unique:true})

db.getCollection("h6vmovie").find({"name.local": "en"})

db.getCollection("h6vmovie").find({},{name:1, download_url:1})

db.getCollection("h6vmovie").update({'page_url':'http://www.hao6v.com/jddy/2017-08-16/MuYeChuanQi.html'},{$set:{'director':['謝寶銳 Baorui Xie']}})

 

 

安裝Myql

sudo apt-get install mysql-server

sudo apt-get install mysql-client

sudo apt-get install libmysqlclient-dev


檢查是否成功:sudo netstat -tap | grep mysql
若是看到有mysql 的socket處於 listen 狀態則表示安裝成功。

 

參考連接: Ubuntu Navicat的安裝配置

相關文章
相關標籤/搜索