MySQL 8.0 설치

JM·2021년 5월 31일
0

MySQL

목록 보기
1/10

✔ MySQL 8.0 Binary 설치 방법


🔨 설치 환경

  • OS : CentOS Linux release 7.9.2009 (Core)
  • DB : MySQL 8.0.23

📌 Download : https://dev.mysql.com/downloads/mysql/


🔨 설치 방법

1. 계정 생성

# groupadd dba
# useradd -g dba mysql

2. 디렉토리 생성

# mkdir -p /mysql/data
# mkdir -p /mysql/log
# chown -R mysql.dba /mysql

3. 설치 파일 압축 해제

# tar -xf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz -C /usr/local
# cd /usr/local
# mv mysql-8.0.23-linux-glibc2.12-x86_64 mysql
# chown -R mysql.dba mysql

4. my.cnf 설정

# vi /etc/my.cnf
[client]
port	= 3306
socket	= /tmp/mysql.sock

[mysqld]
user	= mysql
port	= 3306
basedir	= /usr/local/mysql
datadir	= /mysql/data
log-error= /mysql/log/mysql_error.log
https://dev.mysql.com/doc/refman/8.0/en/server-system-variable-reference.html

5. 데이터 디렉토리 초기화

# su - mysql
$ cd /usr/local/mysql/bin
$ ./mysqld --defaults-file=/etc/my.cnf --initialize-insecure
--initialize : 기본 데이터베이스 생성, 임의의 패스워드로 root 계정을 생성 (패스워드는 로그에서 확인)
--initialize-insecure : 기본 데이터베이스 생성, 빈 암호로 root 계정 생성

6. MySQL 실행

$ ./mysqld_safe --defaults-file=/etc/my.cnf &
$ ps -ef | grep mysqld
mysql      2840   2790  0 17:01 pts/0    00:00:00 /bin/sh ./mysqld_safe --defaults-file=/etc/my.cnf
mysql      3091   2840  9 17:01 pts/0    00:00:02 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/mysql/log/mysql_error.log --pid-file=MySQL-S1.pid --socket=/tmp/mysql.sock --port=3306

7. MySQL 접속

./mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.23 MySQL Community Server - GPL

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

8. MySQL 중지

$ ./mysqladmin -u root -p shutdown
Enter password: 
2021-05-31T08:04:30.631429Z mysqld_safe mysqld from pid file /mysql/data/MySQL-S1.pid ended
[1]+  Done                    ./mysqld_safe --defaults-file=/etc/my.cnf

🔨 기타 설정

1. 서비스 파일 생성

# vi /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
User=mysql
Group=dba
ExecStart=/usr/local/mysql/support-files/mysql.server start

# systemctl daemon-reload
📌 systemctl 명령어를 실행하기 위해서는 일반 계정에 sudo 권한 필요
# visudo
mysql	ALL=NOPASSWD: /usr/bin/systemctl
🔧 systemctl 명령어로 MySQL 실행 / 중지
# su - mysql
$ sudo systemctl start mysqld.service
$ sudo systemctl stop mysqld.service

2. 시스템 환경 변수 등록

$ vi ~/.bash_profile
MySQL=/usr/local/mysql/bin
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$MySQL

$ source ~/.bash_profile
$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/mysql/.local/bin:/home/mysql/bin:/home/mysql/.local/bin:/home/mysql/bin:/usr/local/mysql/bin

3. 설치 보안 향상

  • 루트 계정에 대한 암호 설정
  • 로컬 호스트 외부에서 액세스 할 수 있는 루트 계정 제거
  • 익명 사용자 계정 제거
  • 익명 사용자가 액세스 할 수 있는 테스트 데이터베이스 제거
$ 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) : Y
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) : Y
Success.

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

All done! 
🔧 변경된 root 패스워드로 MySQL 접속
$ mysql -u root -p
Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.23 MySQL Community Server - GPL

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>
profile
오픈소스 DB엔지니어

0개의 댓글