개발자의 서재

docker로 local에 mariaDB 설치해보기 본문

DB

docker로 local에 mariaDB 설치해보기

ironmask431 2022. 5. 23. 16:15

* 로컬에 도커 데스크탑이 먼저 설치되어 있어야 한다. 

 


- 도커-마리아디비 설치
$ docker pull mariadb:10.3.20

- 설치확인
$ docker images

- 마리아디비 컨테이너 실행
$ docker container run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=1234 --name dockerMariadb mariadb:10.3.20

옵션      설명
-------------------------------------------------
-d      detached mode 흔히 말하는 백그라운드 모드
-p      호스트와 컨테이너의 포트를 연결 (포워딩)
-v      호스트와 컨테이너의 디렉토리를 연결 (마운트)
-e      컨테이너 내에서 사용할 환경변수 설정
--name  컨테이너 이름 설정
--it    -i와 -t를 동시에 사용한 것으로 터미널 입력을 위한 옵션 (컨테이너의 표준 입력과 로컬 컴퓨터의 키보드 입력을 연결)
--rm    프로세스 종료시 컨테이너 자동 제거
--link  컨테이너 연결 [컨테이너 명:별칭]

- 마리아디비 컨테이너 확인 (-a 옵션 : 실행중이 아닌 컨테이너도 표시)
$ docker container ls -a 

- 마리아 디비 컨테디이너 접속
$ docker exec -i -t dockerMariadb /bin/bash

- 컨테이너 접속 후 
- mysql버전 확인
$ mysql --version 

-- 마리아 디비 접속
$ mysql -uroot -p1234

-- 데이터베이스 확인
$ show databases;

-- characterset 확인 (characterset들이 latin으로 되어있음)
$ show variables like 'c%';

+----------------------------------+----------------------------+
| Variable_name                    | Value                      |
+----------------------------------+----------------------------+
| character_set_client             | latin1                       |
| character_set_connection         | latin1                       |
| character_set_database           | latin1                     |
| character_set_filesystem         | binary                     |
| character_set_results            | latin1                       |
| character_set_server             | latin1                     |
| character_set_system             | latin1                       |
| character_sets_dir               | /usr/share/mysql/charsets/ |
| check_constraint_checks          | ON                         |
| collation_connection             | utf8_general_ci            |
| collation_database               | latin1_swedish_ci          |
| collation_server                 | latin1_swedish_ci          |
| column_compression_threshold     | 100                        |
| column_compression_zlib_level    | 6                          |
| column_compression_zlib_strategy | DEFAULT_STRATEGY           |
| column_compression_zlib_wrap     | OFF                        |
| completion_type                  | NO_CHAIN                   |
| concurrent_insert                | ALWAYS                     |
| connect_timeout                  | 5                          |
| core_file                        | OFF                        |
+----------------------------------+----------------------------+


-- 컨테이너 모드로 다시 나옴 
$ exit

-- 컨테이너 모드에서 vim설치 후 /etc/mysql/my.cnf 수정 (케릭터셋 수정)
$ apt-get update
$ apt-get install vim 
$ vim /etc/mysql/my.cnf  

-- 아래내용 추가함. 
[mysqld]
skip-character-set-client-handshake
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

[client]
default-character-set = utf8

[mysql]
default-character-set = utf8

[mysqldump]
default-character-set = utf8


-- 컨테이너 재시작
$ docker stop dockerMariadb
$ docker start dockerMariadb

-- 다시 마리아디비 접속하여 "show variables like 'c%';" 실행 시 characterset 변경된것 확인함. 
+----------------------------------+----------------------------+
| Variable_name                    | Value                      |
+----------------------------------+----------------------------+
| character_set_client             | utf8mb4                    |
| character_set_connection         | utf8mb4                    |
| character_set_database           | utf8mb4                    |
| character_set_filesystem         | binary                     |
| character_set_results            | utf8mb4                    |
| character_set_server             | utf8mb4                    |
| character_set_system             | utf8                       |
| character_sets_dir               | /usr/share/mysql/charsets/ |
| check_constraint_checks          | ON                         |
| collation_connection             | utf8mb4_unicode_ci         |
| collation_database               | utf8mb4_unicode_ci         |
| collation_server                 | utf8mb4_unicode_ci         |
| column_compression_threshold     | 100                        |
| column_compression_zlib_level    | 6                          |
| column_compression_zlib_strategy | DEFAULT_STRATEGY           |
| column_compression_zlib_wrap     | OFF                        |
| completion_type                  | NO_CHAIN                   |
| concurrent_insert                | ALWAYS                     |
| connect_timeout                  | 5                          |
| core_file                        | OFF                        |
+----------------------------------+----------------------------+

 

 

--이후 sql 편집기에서 날짜 설정

SET GLOBAL time_zone='Asia/Seoul';

set time_zone='Asia/Seoul';

'DB' 카테고리의 다른 글

[mysql]current_timestamp(), on update current_timestamp()  (0) 2022.06.03
[mariaDB] CREATE 문 예시들  (0) 2022.03.18
[Oracle] 자주쓰는 SQL(DDL,DCL) 정리  (0) 2022.03.06
Comments