사이트 참고 :hub.docker.com/_/mysql/

 

mysql

We and third parties use cookies or similar technologies ("Cookies") as described below to collect and process personal data, such as your IP address or browser information. You can learn more about how this site uses Cookies by reading our privacy policy

hub.docker.com

사전 준비사항 : docker 설치 상태

MySQL Image Download

$ docker pull mysql

# 또는 버전을 명시
$ docker pull mysql:8.0.23

# 둘다 해봄 1번 4번
$ docker images
 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               8.0.23              26d0ac143221        2 days ago          546MB
mysql               latest              26d0ac143221        2 days ago          546MB

Log

Using default tag: latest
latest: Pulling from library/mysql
6f28985ad184: Pull complete 
e7cd18945cf6: Pull complete 
ee91068b9313: Pull complete 
b4efa1a4f93b: Pull complete 
f220edfa5893: Pull complete 
74a27d3460f8: Pull complete 
2e11e23b7542: Pull complete 
fbce32c99761: Pull complete 
08545fb3966f: Pull complete 
5b9c076841dc: Pull complete 
ef8b369352ae: Pull complete 
ebd210f0917d: Pull complete 
Digest: sha256:5d1d733f32c28d47061e9d5c2b1fb49b4628c4432901632a70019ec950eda491
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest

 

 

Docker MySQL 컨테이너 생성 및 실행

  • -V 옵션을 통하여 호스트 경로를 컨테이너의 경로로 마운트 할수 있다고 한다.
    • ex) -v /Mydir:/컨테이너디렉토리
  • 컨테이너 삭제시 데이터도 함께 지워진다고하니 저장소는 외부저장소를 지정하여 사용하도록 한다.
$ docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password --name sqlserver -v /SERVER/mysql/data:/var/lib/mysql mysql:8.0.23 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
3fd45a85dd76590d2e61c40bf1a90e2f8f2677385304923e7c742a6d03027311

# Docker 컨테이너 목록보기
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                               NAMES
3fd45a85dd76        mysql:8.0.23        "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:3306->3306/tcp, 33060/tcp   sqlserver

 

 

MySQL 컨테이너 bash 쉘 접속

docker exec -it sqlserver bash

root@3fd45a85dd76:/#
$ mysql -u root -p
Enter password: 패스워드 입력
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

 

 

'Database' 카테고리의 다른 글

[MongoDB] 관련 정리  (0) 2018.12.19
[MongoDB] API 튜토리얼  (0) 2018.12.19
[MongoDB] mongocxx driver 설치  (0) 2018.12.19
[MongoDB] Ubuntu 18.04 설치하기  (0) 2018.12.19
[MongoDB] 설치하기 (webpage)  (0) 2018.12.19



링크항목들을 정리해본다. 


1. [MongoDB] 설치하기 (webpage)

 - 웹서비스 등록방법

2. [MongoDB] Ubuntu 18.04 설치하기

 - Server 설치 방법

3. [MongoDB] mongocxx driver 설치

 - MongoDB 를 사용하기위한 API Library 설치방법

4. [MongoDB] API 튜토리얼

 - 기본 API 를 사용하기 위한 Qt 예제(첨부파일)



'Database' 카테고리의 다른 글

[Docker] MySQL 설치하기  (0) 2021.03.22
[MongoDB] API 튜토리얼  (0) 2018.12.19
[MongoDB] mongocxx driver 설치  (0) 2018.12.19
[MongoDB] Ubuntu 18.04 설치하기  (0) 2018.12.19
[MongoDB] 설치하기 (webpage)  (0) 2018.12.19

원문 : http://mongocxx.org/mongocxx-v3/tutorial/

참고하도록 


Qt 프레임워크를 통해 MongoDB API 를 사용해보자``


먼저 QtCreator 를 사용하기전에 환경변수를 추가한다. 


$ vim ~/.bashrc

export PATH=$PATH:/opt/pc_qt5.11.1/bin

export PATH=~/bin:/opt/arm-2013.11/bin:/home/kj/DB/mongodb-linux-x86_64-ubuntu1804-4.0.4/bin:$PATH


1. qt 프로젝트 생성

2. qt Build Environment 에 몽고디비가 설치된 환경변수를 생성한다.

 LD_LIBRARY_PATH  = /home/kj/DB/client/lib

PKG_CONFIG_PATH t=/home/kj/DB/client/lib/pkgconfig


3. Application 작성


1). project.pro 파일 맨 아래에 다음 옵션 추가

CONFIG += link_pkgconfig
PKGCONFIG += libmongocxx libbsoncxx


2). 헤더파일 추가

#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/instance.hpp> 
#include <QDebug>
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>


 

3) 소스 코드 작성


    mongocxx::instance inst{}; mongocxx::client conn{mongocxx::uri{}}; bsoncxx::builder::stream::document document{}; auto collection = conn["testdb1"]["testcollection"]; document << "hello" << "world3"; collection.insert_one(document.view()); auto cursor = collection.find({}); for (auto&& doc : cursor) { qDebug()<< QString::fromStdString(bsoncxx::to_json(doc)); } 

 


실행시 DB 에 데이터가 한개씩 추가되는 것을 알 수 있다.




Qt 에서 API 테스트 끝.

qt 버전 5.10.0


테스트 어플리케이션 첨부

MongoDB.tar.gz



'Database' 카테고리의 다른 글

[Docker] MySQL 설치하기  (0) 2021.03.22
[MongoDB] 관련 정리  (0) 2018.12.19
[MongoDB] mongocxx driver 설치  (0) 2018.12.19
[MongoDB] Ubuntu 18.04 설치하기  (0) 2018.12.19
[MongoDB] 설치하기 (webpage)  (0) 2018.12.19

아쉣더 날라가다니...






 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/kj/DB/client ../


-- Auto-configuring bsoncxx to use MNMLSTC for polyfills since C++17 is inactive

CMake Error at src/bsoncxx/CMakeLists.txt:81 (find_package):

  Could not find a configuration file for package "libbson-1.0" that is

  compatible with requested version "1.13.0".


  The following configuration files were considered but not accepted:


    /usr/lib/x86_64-linux-gnu/cmake/libbson-1.0/libbson-1.0-config.cmake, version: 1.9.2



libbson 버전을 변경해야 될거 같다. 현재 사용버전은 1.9.2  -> 1.13





오 생성됨 

   "/home/kj/DB/Driver/libbson/mongo-c-driver-1.12.0/build/src/libbson/libbson-1.0.so.0.0.0"

  to "/usr/local/lib/libbson-1.0.so.0.0.0".


가보자 이제 다시 젤첨 코드를 빌드한다.


아앗 1.13 이아니라 1.12 를 받았다. ......................

다시 다운로드  

$ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.13.0/mongo-c-driver-1.13.0.tar.gz


빌드진행 설치 ->>>

  cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/kj/DB/client ../


서설치가 되었다.!!!



정리해보면 다음과 같다.

mongo-c-driver-1.13.0 설치후 mongo-cxx-driver 를 설치한다.



설치된 경로 확인


/home/kj/DB/client 


패키지 pc 파일 정보 : /home/kj/DB/client/lib/pkgconfig

 - libbsoncxx.pc  libmongocxx.pc



코드 테스트해보도록 하자 : 예제참고링크


환경변수 등록



 

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/kj/DB/client/lib/pkgconfig

c++ --std=c++11 test.cpp -o test $(pkg-config --cflags --libs libmongocxx)

 ./test 

./test: error while loading shared libraries: libmongocxx.so._noabi: cannot open shared object file: No such file or directory



export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/kj/DB/client/lib



./test 

{ "_id" : { "$oid" : "5c19ea2ebdf13c4bca573d92" }, "hello" : "world" }


동작 확인 완료

..



기본환경변수 패스에 추가해 준다. vim ~/.bashrc


export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/home/kj/DB/client/lib/pkgconfig

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/kj/DB/client/lib



테스트 코드는 아래 링크를 따라가세요.

[MongoDB] API 튜토리얼 



'Database' 카테고리의 다른 글

[Docker] MySQL 설치하기  (0) 2021.03.22
[MongoDB] 관련 정리  (0) 2018.12.19
[MongoDB] API 튜토리얼  (0) 2018.12.19
[MongoDB] Ubuntu 18.04 설치하기  (0) 2018.12.19
[MongoDB] 설치하기 (webpage)  (0) 2018.12.19


몽고DB 설치하기


참고 페이지 : https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu-tarball/



나의 우분투버전은 Ubuntu 18.04 (Bionic 버전이다.)



MongoDB 를 설치하기위해서는 아래 패키지를 설치한다.


 sudo apt-get install libcurl4 openssl



1. 설치 파일 다운로드 :https://www.mongodb.com/download-center/community?jmp=docs



 2. 설치방법


1) 압축 파일 해제

  /home/db  $ tar xvf mongodb-linux-x86_64-ubuntu1804-4.0.4.tgz

2) 실행 폴더 환경변수 등록

export PATH=$PWD: (Mongodb/bin 패스)


나의 경우는 export PATH=$PWD:/home/kj/DB/mongodb-linux-x86_64-ubuntu1804-4.0.4/bin

환경변수 ~/.bashrc 파일안에 설정하였다.

3) data 와 log 디렉토리 생성

 sudo mkdir -p /MongoDB/db

 sudo mkdir -p /var/log/mongodb


4). 실행

sudo ./mongod --dbpath /MongoDB/db --logpath /var/log/mongodb/mongod.log --fork

 2018-12-19T15:06:28.614+0900 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'

about to fork child process, waiting until server is ready for connections.

forked process: 5739

child process started successfully, parent exiting




5.) ./mongo 를 통해 접속가능한지 확인

MongoDB shell version v4.0.4

connecting to: mongodb://127.0.0.1:27017

Implicit session: session { "id" : UUID("d1753a27-7745-47ef-9693-8696ca35a337") }

MongoDB server version: 4.0.4

Server has startup warnings: 

2018-12-19T15:06:28.622+0900 I STORAGE  [initandlisten] 

2018-12-19T15:06:28.622+0900 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine

2018-12-19T15:06:28.622+0900 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] 

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] 

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.

2018-12-19T15:06:29.847+0900 I CONTROL  [initandlisten] 

---

Enable MongoDB's free cloud-based monitoring service, which will then receive and display

metrics about your deployment (disk utilization, CPU, operation statistics, etc).


The monitoring data will be available on a MongoDB website with a unique URL accessible to you

and anyone you share the URL with. MongoDB may use this information to make product

improvements and to suggest MongoDB products and deployment options to you.


To enable free monitoring, run the following command: db.enableFreeMonitoring()

To permanently disable this reminder, run the following command: db.disableFreeMonitoring()




사용자 를 등록해준다.

> usb admin

2018-12-19T15:11:15.962+0900 E QUERY    [js] SyntaxError: missing ; before statement @(shell):1:4

> use admin

switched to db admin

> db.createUser({user: "root", pwd: "XXX!",roles:[{role: "root",db:"admin"}]});

Successfully added user: {

"user" : "root",

"roles" : [

{

"role" : "root",

"db" : "admin"

}

]

}



활용 테스트는 나중에. 

'Database' 카테고리의 다른 글

[Docker] MySQL 설치하기  (0) 2021.03.22
[MongoDB] 관련 정리  (0) 2018.12.19
[MongoDB] API 튜토리얼  (0) 2018.12.19
[MongoDB] mongocxx driver 설치  (0) 2018.12.19
[MongoDB] 설치하기 (webpage)  (0) 2018.12.19


Ubuntu 18.04 에 MongoDB 를 설치 해 보기로 한다.


공식사이트에서 회원가입


1. 완료시 다음과 같은 화면이 뜬다.


2. 선택항목들은 다음과 같다.

Cloud Provider & Region

 3가지 항목이 존재한다. 

 AWS , Google Cloud Platform, Azure


Additional Settings : MongoDB4.0 , No Backup  

백업기능을 사용하려면 돈이필요하나 보다. ㅎ


 - Cluster Name 을 설정한다. IVIS 로 설정


3.  클러스터 생성중. 7 ~ 10분정도 소요


4. 완료된 화면





정리는 나중에.. tobe




'Database' 카테고리의 다른 글

[Docker] MySQL 설치하기  (0) 2021.03.22
[MongoDB] 관련 정리  (0) 2018.12.19
[MongoDB] API 튜토리얼  (0) 2018.12.19
[MongoDB] mongocxx driver 설치  (0) 2018.12.19
[MongoDB] Ubuntu 18.04 설치하기  (0) 2018.12.19

+ Recent posts