이것저것 적어보는 블로그

AWS EC2 mysql 설치 & 초기 설정 본문

개발&코딩

AWS EC2 mysql 설치 & 초기 설정

dona0408 2023. 7. 2. 23:19
반응형

EC2에 mysql을 설치해서 이용하려니 설치부터 초기 설정까지 문제 투성이라 열심히 찾아가며 세팅을 했었다.

언젠간 또 찾아볼 수도 있고 같은 문제로 검색을 하는 사람들에게 도움이 되었으면 해서 글을 남긴다.

EC2 인스턴스를 생성 후 터미널을 이용해 SSH로 EC2서버와 연결해도 되고 웹에서 연결 버튼을 눌러 터미널을 띄우는 방법도 있다. 어떤 것이던 상관없으니 편한 걸로 하면 된다.

  1. sudo apt-get update 명령을 통해 패키지 정보를 업데이트
  2. sudo apt-get dist-upgrade 로 패키지 의존성 검사 및 업데이트도 진행한다.
  3. sudo apt-get install mysql-server 를 입력해서 mysql을 설치 후 실행하면 아래 사진처럼 나온다.

root계정에 대한 비밀번호 설정이 없었는데….? 하고 당황하여 검색해 보니 mysql_secure_installation 을 입력해서 세팅하면 된다고 한다. 그런데 또 root 계정을 물어본다… 아놔

sudo mysql 이라고 입력하면 거짓말 같이 로그인이 된다. 이때 아래 명령어를 입력해서 새로운 비밀번호를 설정해 주자.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '새로운비밀번호';

정상적으로 설정이 되면 더 이상 sudo mysql 명령으로 로그인이 되지 않는다.

mysql -u root -p 를 이용해 로그인하면 잘 된다.

이대로 사용하면 될 것 같은데 다들mysql_secure_installation 을 다시 하길래 따라 했다. 이젠 root 비밀번호 설정했으니 암호 입력하고 진행하면 된다.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:

비밀번호 복잡성 유무 설정으로, 복잡한 비밀번호를 하려면 y, Y 중 아무거나 입력하고 엔터를 하면 되고 아니라면 그냥 엔터 해도 된다. → 저는 No 선택하고 넘겼습니다.

Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :

방금 바꾸고 온 비밀번호를 바꿀 거냐고 묻는 질문. secure_installation이 처음부터 안 막혔다면 여기서 바꿨을 텐데 mysql 가서 열심히 바꾸고 온 거라 바로 No

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :

익명 유저 제거를 원한다면 YES. → YES 하고 넘겼다.

Yes - 접속 시 "mysql -u root"처럼 -u 옵션 필요

No - 접속 시 "mysql”처럼 -u 옵션 불필요

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :

localhost만 root로 접속할 수 있는지, 아니면 외부(원격)에서도 root로 접속할지 설정 → No 했습니다.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :

Test DB 유지 여부 설정. 뭘 해도 상관이 없다.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

마지막으로 지금까지 설정한걸 바로 적용하는지 묻는다. 당연 Y

모든 설정이 끝났다. 이제 mysql을 마음껏 사용하면 된다!!

 

이 문제를 해결하며 참고했던 사이트

https://seong6496.tistory.com/322

반응형
Comments