기록

MySQL 설치 & DB툴(DB IDE) 연결 본문

DB

MySQL 설치 & DB툴(DB IDE) 연결

mnmhbbb 2024. 2. 9. 00:28

데이터베이스 관리 시스템(DBMS) 중 하나인 MySQL을 사용하여 DB에 대해 공부하고 있는데, 맨처음 설치하고 세팅하는 과정을 간단하게 정리하고 넘어가려고 한다.

 

1. MySQL 설치하기

brew install mysql
mysql --version

 

2. MySQL 서버 시작하기

mysql.server start

서버 실행 성공

 

2.1 MySQL 서버 실행 종료 & 재시작

mysql.server stop
mysql.server restart

+) 

  • 기본적으로 MySQL 서버를 켜둔 상태에서(네트워크 접속한 상태에서) 데이터베이스 계정(현재의 경우, 기본적으로 생성되는 root)에 로그인하는 흐름인데,
  • 여기서 계정이란, 데이터베이스를 생성하고 관리할 수 있는 권한을 가진 사용자를 의미한다.
  • 한 계정에서 여러 데이터베이스를 생성하고 관리할 수 있다.

 

2.2 brew services start mysql과 mysql.server start의 차이점?

  • 이들은 MySQL 서버를 실행하는 두 가지 방법이다.
  • 전자는 homebrew를 통해 MySQL을 관리하는 방법으로, 백그라운드에서 실행된다.
  • 시스템 재부팅 시에 사용자가 명시적으로 설정하지 않아도 자동으로 시작할 수 있게 설정할 수 있다.
  • MySQL을 *데몬으로 실행하고자 할 때 이 방식을 사용한다.
  • 데몬(Daemon): 운영체제의 백그라운드 상태에서 계속 실행되는 프로그램
  • 후자는 MySQL 스크립트를 사용하는 방식으로, 백그라운드에서 실행하려면 옵션 명령어를 추가로 입력해야 한다.
  • 기본적으로 사용자의 세션에 종속되어 동작한다. 시스템 재부팅 시에 MySQL 서버가 자동으로 실행되지 않음.
  • 여기서 세션이란, 로그인하여 로그아웃을 할 때까지의 기간을 의미함.
brew services start mysql
brew services restart mysql
brew services list
brew services stop mysql

 

 

 

3. MySQL 초기 설정하기

mysql_secure_installation
  • 계정 로그인 후 초기 설정을 할 수 있다.
  • 지금 이 설정들은 나중에도 수정할 수 있다.

 

3.1 복잡한 비밀번호 생성을 권장하고 비밀번호 강도 검사를 하는 컴포넌트가 있는데 이것을 세팅할 건지?

Securing the MySQL server deployment.

Enter password for user 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 or n

로컬에서 테스트만 할 거라서 n 선택함.

 

3.2 자동으로 익명 유저가 생성됐는데 제거할 건지?

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) : y
Success.

 

 

3.3 root 계정만 localhost로 접근할 수 있다. 다른 게스트들이 원격 접속으로 roor 계정에 접근하는 것을 허락할 건지?

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) : n

 

3.4 기본적으로 설치되어 있는 test라는 데이터베이스와 이것의 접근 권한을 제거할 건지?

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) : y

 

3.5 권한 테이블을 다시 로드하여 변경사항을 즉시 적용할 수 있다. 권한 테이블을 다시 로드할 건지?

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

 

 

 

4. MySQL 로그인

mysql -u root -p
  • -u는 User, -p는 Password를 의미한다.
  • user: root
  • password: 초기설정한 비밀번호를 추후 입력

 

 

5. MySQL 로그아웃

mysql> exit
mysql> quit

이 명령어는 root 계정 로그아웃일 뿐, MySQL 서버를 종료한 것은 아님.

 

 

6-1. Database IDE 실행하기 - DBeaver

새 데이터베이스 연결하기(데이터베이스 계정 정보를 입력하여 연결):

MySQL 선택

 

아까 설정했던 user, password를 입력한다:

위 데이터들이 기본적으로 입력돼 있었고, 내가 설정한 Password만 추가로 입력하였음.
참고로, MySQL의 대표 port는 3306

그 다음 좌측 하단의 Test Connection을 클릭하면 연결됐다는 팝업이 뜬다:

최종적으로 완료 버튼으로 새 데이터베이스 연결을 마침.

 

 

6-2. Database IDE 실행하기 - MySQL Workbench

마찬가지로 기본값들이 입력되어 있고, Connection Name만 내가 원하는 이름으로 설정하고,
Test Connection을 클릭하면 내가 설정한 비밀번호를 입력하라고 뜬다.
입력하면 연결이 성공했다는 창이 뜬다.

 

 

 

참조: 

 

velog

 

velog.io

Comments