MySQL 설치 및 초기 설정

IT Newbie·2022년 4월 2일
1

2022.3.12.

homebrew로 MySQL 패키지 설치 방법

MySQL 패키지 검색

% brew search mysql
==> Formulae
automysqlbackup               mysql-client                  mysql-sandbox                 mysql@5.7
mysql                         mysql-client@5.7              mysql-search-replace          mysqltuner
mysql++                       mysql-connector-c++           mysql@5.6                     qt-mysql
==> Casks
mysql-connector-python                  mysql-utilities                         navicat-for-mysql
mysql-shell                             mysqlworkbench ✔                        sqlpro-for-mysql

MySQL 설치 방법

# 최신 mysql 패키지를 다운
% brew install mysql

==> mysql
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -u root

To restart mysql after an upgrade:
  brew services restart mysql
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql

# mysql@버전 : 원하는 버전을 선택하여 다운
% brew install mysql@5.7

# mysql-client는 커맨드라인에서 mysql 서버 접속시 사용
% brew install mysql-client

# GUI for MySQL
% brew install --cask mysqlworkbench

MySQL 설치 확인 방법

# brew list를 통해 설치된 항목을 조회
% brew list

==> Formulae
mysql

MySQL 삭제 방법

% brew remove mysql

MySQL 초기 설정 방법

환경 변수 추가

  • bash shell이 아닌 [M1 MacBook Air macOS Monterey 12.2.1] zsh shell을 기준으로 작성하였습니다
% echo 'export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
% echo 'export PATH="/opt/homebrew/opt/mysql/bin:$PATH"' >> ~/.zshrc

환경 변수 적용

% source ~/.zshrc

MySQL 서버 실행, 중지

# MySQL 서버 실행
% mysql.server start

Starting MySQL
. SUCCESS! 

# MySQL 서버 중지
% mysql.server stop

Shutting down MySQL
. SUCCESS! 

MySQL 설정

MySQL 기본적인 보안을 강화 설정을 하기 위해서는 mysql_secure_installation 명령어 입력

# MySQL 기본적인 보안을 강화 설정을 하기 위해서 `mysql_secure_installation` 명령어를 입력
% mysql_secure_installation

비밀번호 유형 선택

  • 비밀번호 가이드 설정에 대한 질문

    • Yes : 복잡한 비밀번호 설정

    • No : 쉬운 비밀번호 설정

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN 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 plugin?

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

비밀번호 설정

  • 사용할 새로운 비밀번호를 입력

  • 비밀번호 : 0000

Please set the password for root here.

New password:

Re-enter new password:

사용자 설정

  • Yes : 접속하는 경우 mysql -u root처럼 -u 옵션 필요
  • No : 접속하는 경우 mysql처럼 -u 옵션 불필요
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

원격 접속 설정

  • 다른 IP에서 root 아이디로 원격접속을 허용하는지에 대한 설정

    • Yes : 원격접속 불가능

    • No : 원격접속 가능

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

TEST 데이터베이스 설정

  • Test 데이터베이스를 설정하는 질문

    • Yes : Test 데이터베이스 제거

    • No : 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) : Yes

변경된 권한을 테이블에 적용하는 설정

  • 변경된 권한을 테이블에 적용하는 설정에 대한 질문

    • Yes : 적용 시킨다

    • No : 적용시키지 않는다

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

설정 완료

  • All done!이 뜨면 모든 설정 완료

    % mysql_secure_installation
    
    Securing the MySQL server deployment.
    
    Connecting to MySQL using a blank password.
    
    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:  no
    Please set the password for root here.
    
    New password: 
    
    Re-enter new password: 
    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
    Success.
    
    
    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) : no
    
     ... skipping.
    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) : yes
     - Dropping test database...
    Success.
    
     - Removing privileges on test database...
    Success.
    
    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) : yes
    Success.
    
    All done! 

MySQL DB 로그인/로그아웃

MySql 로그인

# 서버 실행 후 
% mysql -u root -p
Enter password:
  • 정상적으로 로그인이 되면 mysql> 나옵니다.
% mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.35 Homebrew

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>

MySql 로그아웃

mysql> exit or quit
Bye

MySQL 실행 절차

# MySQL 서버 시작 :
% mysql.server start

# MySQL DB 로그인 :
% mysql -u root -p
Enter password: 0000

# MySQL DB 로그아웃 :
mysql> exit 또는 quit

# MySQL 서버 종료 :
% mysql.server stop

0개의 댓글