본문 바로가기
DEV/개발환경

WSL에 MySQL 설치하기

by 올커 2024. 6. 23.

 

WSL에 MySQL 설치하기

 

1) 우분투 패키지 업데이트

sudo apt-get update

 

2) MySQL 설치

sudo apt-get install mysql-server -y

 

 

3) 보안을 위한 secure installation 설치

sudo 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?

## 암호 검증 여부시 → y
Press y|Y for Yes, any other key for No: y

 

 - 암호 생성시 암호 복잡도 지정 

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

## 암호 생성시 암호 복집도 지정 → 지정 후 root계정에 대한 암호 생성
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0

 

 - 기본 제공하는 익명 유저(anonymous user) 삭제 여부 → 삭제

Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.

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.

## anonymous user 제거 여부 → 제거

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

 

 - 외부로부터 접근 허용 여부(기본 : root 계정은 localhost에서만 접근 허가) → 외부로부터 막으려면 y 입력

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

 

 

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

 

4) MySQL 접속

sudo mysql


##########################################################################
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.37-0ubuntu0.22.04.3 (Ubuntu)

Copyright (c) 2000, 2024, 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'pa$$w0rd';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

 

5) 데이터베이스 생성 SQL 입력, 테스트 데이터베이스 생성

mysql> CREATE DATABASE IF NOT EXISTS etlmysql;
Query OK, 1 row affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| etlmysql           |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.01 sec)

 

 

6) 생성된 데이터베이스 권한 지정

mysql> CREATE USER 'user01'@'localhost' IDENTIFIED BY 'pa$$w0rd';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON ETLMySQL.* to user01@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW GRANTS FOR 'user01'@'localhost';
+----------------------------------------------------------------+
| Grants for everreal@localhost                                  |
+----------------------------------------------------------------+
| GRANT USAGE ON *.* TO `user01`@`localhost`                   |
| GRANT ALL PRIVILEGES ON `ETLMySQL`.* TO `user01`@`localhost` |
+----------------------------------------------------------------+
2 rows in set (0.00 sec)

 

 

 

반응형

댓글