MySQL 5.x 설치 (1)

MySQL

Install

Ubuntu 16 x64, armhf 등에서 패키지로 설치

1

Start

mysql-server 를 설치하며 만든 root 사용자 패스워드를 사용해서 데이터베이스에 접속한다.

1
2
3
4
5
6
7
8
9
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26 MySQL Community Server (GPL)

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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

데이터베이스 보기

1
2
3
4
5
6
7
8
9
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+

mysql shell 에서 root 패스워드 변경

1
2
mysql> update user set password=password('PASSWORD') where user = ‘root’;
mysql> flush privileges;

MySQL 설정

MySQL에서 설정파일을 읽는 순서는 다음과 같다.

/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/mysql/etc/my.cnf
~/.my.cnf

/etc/my.cnf

utf-u 문자셋을 기본으로 설정하기 위해서 my.cnf 파일을 다음 같이 사용한다.

만약 외부에서 데이터베이스를 접속하면 설정의 bind-address 막아 주어야 한다. 그렇지 않으면 클라이언트에서 접속 시도시 다음 2003 에러가 난다.[^2]

1
ERROR 2003 (HY000): Can't connect to MySQL server on

MySQL 설정 파일에서 문자셋을 변경할 수 있다. 다믕 같이 자신의 my.cnf 파일을 작성한다. client, mysqld, mysql 에 대해서 utf8 사용을 선언해 준다.

1
2
3
4
5
6
7
8
9
10
11
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/var/lib

[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[client]
..
default-character-set=utf8

[mysqld]
character-set-client-handshake=FALSE
init_connect="SET collation_connection = utf8_general_ci"
init_connect="SET NAMES utf8"
character-set-server=utf8
collation-server=utf8_general_ci

[mysqldump]
default-character-set=utf8

[mysql]
default-character-set=utf8

Mysql Secure Installation

1
# mysql_secure_installation

SSL

SSL을 통한 암호화 접속을 허용하려면 서버측과 클라이언트 측 모두 인증 파일을 만들어야 한다.

https://dev.mysql.com/doc/refman/5.7/en/using-encrypted-connections.html

서버측 인증

인증 --ssl 옵션으로 파일은,

  • –ssl-ca identifies the Certificate Authority (CA) certificate.

  • –ssl-cert identifies the server public key certificate. This can be sent to the client and authenticated against the CA certificate that it has.

  • –ssl-key identifies the server private key.

mysql_ssl_rsa_setup 유틸리티를 실행하면 data 디렉토리 밑에 생성해 준다.[^5]

ca.pem
server-cert.pem
server-key.pem

파일을 생성해 준다.

1
2
3
4
5
[mysqld]

ssl-ca=/var/mysql/ca.pem
ssl-cert=/var/mysql/server-cert.pem
ssl-key=/var/mysql/server-key.pem

openssl 이용

openssl을 이용해 수동으로 키를 생성한다. [^6]

1
2
3
#cd /etc/mysql
#openssl genrsa 2048 > ca-key.pem

ca certificate 생성

1
openssl req -new -x509 -nodes -days 1000 -key ca-key.pem > ca-cert.pem
1
openssl req -newkey rsa:2048 -days 1000 -nodes -keyout server-key.pem > server-req.pem

private key를 생성합니다.

[root@EDYDR51P0 newcerts]# openssl x509 -req -in server-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem

증서를 가지고 SSL 로 접속할려면 요런 옵션으로 접속하면 된다.

mysql -u root -p –ssl –ssl-ca=c:\cert\cert.pem

참조

https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04

[^5]: Creating SSL & RSA Certificates and keys
[^6]: [Creating SSL Certificates and keys Using openssl](6.4.3.2 Creating SSL Certificates and Keys Using openssl)