01. 설치 및 기본 설정

패키지 설치

$ sudo apt install mysql-server
$ sudo mysql_secure_installation

데이터베이스 및 사용자 추가

MySQL의 root 로그인 허용

MySQL 5.7 이후 버전에서는 MySQL의 root 사용자는 auth_socket 플러그인을 이용하여 인증 로그인합니다.

$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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의 root 사용자에게 비밀번호를 부여하고 로그인을 허용하기 위한 방법을 살펴봅니다.

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
+------------------+-------------------------------------------+-----------------------+-----------+
| user             | authentication_string                     | plugin                | host      |
+------------------+-------------------------------------------+-----------------------+-----------+
| root             |                                           | auth_socket           | localhost |
| mysql.session    | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys        | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *DD2DA5469C071342060E617E66AA503D7A335FB0 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)

예시에서 보면 root 사용자의 플러그인이 auth_socket으로 설정되어 있는 것을 확인할 수 있습니다. 이제 이것을 mysql_native_password로 변경합니다.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
mysql> exit

이제 MySQL의 root 사용자로 아래와 같이 비밀번호를 입력으로 로그인할 수 있습니다.

$ mysql -uroot -p

그러나 MySQL의 root 사용자를 비밀번호 접속 허용하는 것은 보안상 권장되지 않습니다.

testdb 데이터베이스 추가

testdb 데이터베이스를 생성합니다.

mysql> CREATE DATABASE testdb CHARACTER SET utf8 COLLATE utf8_general_ci;

ham@localhost 사용자 생성 및 testdb 데이터베이스 접속 권한 부여

MySQL의 ham@localhost 사용자를 password 비밀번호로 추가합니다.

mysql> CREATE USER ham@localhost IDENTIFIED BY 'password';

이제 ham@localhost 사용자에게 testdb 데이터베이스의 모든 테이블에 권한을 부여합니다.

mysql> GRANT ALL PRIVILEGES ON testdb.* TO ham@localhost;
mysql> FLUSH PRIVILEGES;

ham@localhost 사용자로 testdb 데이터베이스 접속

$ mysql -uham -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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>

ham@localhost 사용자의 비밀번호 변경 및 삭제

ham@localhost 사용자의 비밀번호를 new_password로 새로 아래와 같이 변경할 수 있습니다.

mysql> ALTER USER ham@localhost IDENTIFIED BY 'new_password';

불필요한 사용자의 경우 아래와 같이 삭제할 수 있습니다.

mysql> DROP USER ham@localhost;

testdb 데이터베이스 삭제

불필요한 데이터베이스의 경우 아래와 같이 데이터베이스를 삭제할 수 있습니다.

mysql> DROP DATABASE testdb;

Django 최적화 옵션

원격 접속 허용

최종 수정일시: 2019-02-14 21:02

blog comments powered by Disqus