본문 바로가기

AWS

EC2에 설치한 mariaDB 계정 설정 + 권한 설정하기

Docker기반의 mariaDB 설치가 궁금하다면

이전 포스팅에 했던 EC2에 mariaDB docker를 이용하여 설치하기편을 확인해주길 바란다.

2024.08.25 - [AWS] - AWS EC2에 Docker를 이용하여 MariaDB 설치

 

AWS EC2에 Docker를 이용하여 MariaDB 설치

$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmariadb latest 92520f86618b 9 days ago 407MB​$docker --versionec2에 프로젝트 배포하기까지의 여정을 공유하고자 글을 쓰게 되었습니다. 사용 툴1. XShell ( ssh를 통한 ec2

chbong.tistory.com

 

이번에는 내가 사용할 mariaDB의 계정과 그 권한을 설정하는 방법에 대하여 포스팅 해보겠다.

 

첫번째는 mariaDB의 접속이다.

mariadb -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 11.5.2-MariaDB-ubu2404 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>

 

이전 포스팅에 설정했던 password를 입력하면 잘 접속될것이다.

현재 선택되어있는 database가 없어서 MariaDB[(none)] 이라고 나오는데 정상적이다.

 

현재 내가 가지고 있는 database 확인하기

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.001 sec)

 

 

 

다음으로 use mysql을 통하여 mysql Database에 접근하기

 

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select host,user,password from user;
+-----------+-------------+-------------------------------------------+
| Host      | User        | Password                                  |
+-----------+-------------+-------------------------------------------+
| localhost | mariadb.sys |                                           |
| localhost | root        | *A4B6157319038722C8886EBFCF |
| %         | root        | *A4B6157319038732C886EBFCF |
| 127.0.0.1 | healthcheck | *669651DBE417D0775B4E83E15 |
| ::1       | healthcheck | *669651DBE417D0D80B775B49EE5 |
| localhost | healthcheck | *669651DBE417D00B775B49EE83E15 |
+-----------+-------------+-------------------------------------------+
6 rows in set (0.001 sec)

 중요하진 않지만, 패스워드는 일부씩 지워서 간격이 맞지않는다 

 

이렇게 user와 host를 검색할수 있다.

 

이제 유저를 생성해보겠다.

아래와 같이 명령어를 입력하면 된다.

create user '유저이름'@'호스트' identified by '비밀번호';

MariaDB [mysql]> create user 'ch'@'%' identified by '1234';
Query OK, 0 rows affected (0.001 sec)

 

create user가 되었으면 권한을 설정해주어야한다.

모든권한을 허용하는 옵션으로 설정하였는데, 사용자에 따라서 어떤 권한에 맞춰줄건지에 대해서는 직접 확인하여 명령어를 쳐보길 바란다.

MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'ch'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.001 sec)

 

이렇게까지 하면 권한이 설정이 완료되었는데, 여기서 다했다고 생각하고 끝내면 아무일도 벌어지지 않는다.

그 이유는 database 에서 값 수정하고 commit을 안했을때와 동일한 느낌이다.

* 권한 설정한걸 flush 즉 commit 처리 해주어야한다.

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

 

이렇게까지하면 권한과 user설정도 완료되었다.

 

잘 생성되었는지 확인하기 위해 아래와 같이 다시한번 user를 검색해준다.

MariaDB [mysql]> select host,user,password from user;
+-----------+-------------+-------------------------------------------+
| Host      | User        | Password                                  |
+-----------+-------------+-------------------------------------------+
| localhost | mariadb.sys |                                           |
| localhost | root        | *A4B6157319038724E3 |
| %         | root        | *A4B6157319038724E35 |
| 127.0.0.1 | healthcheck | *669651DBE417D0F6F30 |
| ::1       | healthcheck | *669651DBE417D0F6F3051FAD8 |
| localhost | healthcheck | *669651DBE417D0F6F3051FAD |
| %         | ch          | *A4B6157319038724E3560 |
+-----------+-------------+-------------------------------------------+
7 rows in set (0.001 sec)

 

이전에 생성했던 ch의 user가 생성되었고 정상적으로 접속이 가능한걸 확인할 수 있다.

 

root@4e522ae7abb0:/# mariadb -u ch -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 11.5.2-MariaDB-ubu2404 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>

 

이젠 mariadb -u root 가 아닌 mariadb -u ch 로 변경하여 mariadb에 접근이 가능하다.

'AWS' 카테고리의 다른 글

EC2에 Docker 로 배포하기 !  (0) 2024.08.25
AWS EC2에 git설치 후 private git 당겨오기  (0) 2024.08.25
AWS RDS 프리티어 생성  (0) 2024.08.25
AWS EC2에 Docker를 이용하여 MariaDB 설치  (0) 2024.08.25