CentOS 7에 MySQL 5.6 설치 및 초기 설정 가이드

  1. MySQL 5.6 소스 코드 패키지 다운로드
mkdir /mysql_install
cd /mysql_install
wget https://cdn.mysql.com//Downloads/MySQL-5.6/MySQL-5.6.49-1.el7.x86_64.rpm-bundle.tar
  1. 지정된 폴더(mysql_rpm)에 압축 해제
root@centos7-mysql:/mysql_install#mkdir mysql_rpm
root@centos7-mysql:/mysql_install#tar -xf MySQL-5.6.49-1.el7.x86_64.rpm-bundle.tar -C ./mysql_rpm
root@centos7-mysql:/mysql_install#ls
MySQL-5.6.49-1.el7.x86_64.rpm-bundle.tar  mysql_rpm
root@centos7-mysql:/mysql_install#cd mysql_rpm/
root@centos7-mysql:/mysql_install/mysql_rpm#ls
MySQL-client-5.6.49-1.el7.x86_64.rpm  MySQL-embedded-5.6.49-1.el7.x86_64.rpm  MySQL-shared-5.6.49-1.el7.x86_64.rpm         MySQL-test-5.6.49-1.el7.x86_64.rpm
MySQL-devel-5.6.49-1.el7.x86_64.rpm   MySQL-server-5.6.49-1.el7.x86_64.rpm    MySQL-shared-compat-5.6.49-1.el7.x86_64.rpm
root@centos7-mysql:/mysql_install/mysql_rpm#
  1. yum을 사용하여 mysql_rpm 디렉토리의 모든 rpm 패키지 설치 및 의존성 해결
yum localinstall ./*
  1. 설치 완료 후 MySQL 설정 파일 확인 및 수정
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql    # MySQL 데이터 저장 경로
socket=/var/lib/mysql/mysql.sock    # MySQL 실행 시 프로세스 파일
# 보안 위험 방지를 위해 심볼릭 링크 비활성화 권장
symbolic-links=0
# systemd 사용 시 user 및 group 설정은 무시됨
# 다른 사용자 또는 그룹으로 mysqld를 실행해야 하는 경우
# http://fedoraproject.org/wiki/Systemd의 지침에 따라
# systemd 단위 파일을 사용자 정의하십시오

[mysqld_safe]    # 로그 저장 위치
#log-error=/var/log/mariadb/mariadb.log    mariadb를 mysql로 변경
log-error=/var/log/mysql/mysql.log
#pid-file=/var/run/mariadb/mariadb.pid    mariadb를 mysql로 변경
pid-file=/var/run/mysql/mysql.pid

#
# 설정 디렉토리의 모든 파일 포함
#
!includedir /etc/my.cnf.d
  1. MySQL 서비스 시작 및 3306 포트 확인
root@centos7-mysql:/mysql_install/mysql_rpm#systemctl start mysql
root@centos7-mysql:/mysql_install/mysql_rpm#netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2408/sshd: /usr/sbi
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      875/rpcbind
tcp        0      0 0.0.0.0:10032           0.0.0.0:*               LISTEN      1578/java
tcp6       0      0 :::22                   :::*                    LISTEN      2408/sshd: /usr/sbi
tcp6       0      0 :::3306                 :::*                    LISTEN      89110/mysqld
tcp6       0      0 :::111                  :::*                    LISTEN      875/rpcbind
udp        0      0 0.0.0.0:68              0.0.0.0:*                           23060/dhclient
udp        0      0 0.0.0.0:111             0.0.0.0:*                           875/rpcbind
udp        0      0 10.22.2.160:123         0.0.0.0:*                           879/ntpd
udp        0      0 127.0.0.1:123           0.0.0.0:*                           879/ntpd
udp        0      0 0.0.0.0:123             0.0.0.0:*                           879/ntpd
udp        0      0 0.0.0.0:613             0.0.0.0:*                           875/rpcbind
udp6       0      0 :::111                  :::*                                875/rpcbind
udp6       0      0 :::123                  :::*                                879/ntpd
udp6       0      0 :::613                  :::*                                875/rpcbind
root@centos7-mysql:/mysql_install/mysql_rpm#
  1. MySQL 초기화. MySQL 5.6은 설치 후 자동으로 루트의 임시 비밀번호를 생성하며, 이는 ~/.mysql_secret 파일에 저장됩니다.
root@centos7-mysql:/mysql_install/mysql_rpm#cat ~/.mysql_secret
# Mon Feb 20 21:19:08 2023 (local time)에 설정된 루트 사용자의 임의 비밀번호: WHWA*******PNZSEd
  1. 두 가지 방법으로 초기 비밀번호 변경
root@centos7-mysql:/mysql_install/mysql_rpm#mysqladmin -uroot -pWHWA0*****SEd password newpass123
Warning: Using a password on the command line interface can be insecure.    # 경고: 이 방법으로 비밀번호를 설정하면 history에 비밀번호가 표시될 수 있습니다.
root@centos7-mysql:/mysql_install/mysql_rpm#

보안 방법: 임시 비밀번호로 MySQL에 접속한 후 비밀번호 변경 명령어 사용

root@centos7-mysql:/mysql_install/mysql_rpm#mysql -uroot -p
Enter password:

mysql> update mysql.user set password=password('securepass2023') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0
mysql> flush privileges;    # 권한 정보 새로고침 후 exit로 종료
Query OK, 0 rows affected (0.00 sec)
mysql>exit
Bye
  1. JumpServer 데이터베이스 생성 및 한글 지원 형식으로 저장
root@centos7-mysql:/mysql_install/mysql_rpm#mysql -uroot -p
Enter password:

mysql> create database jumpserver default charset 'utf8' collate 'utf8_bin';
Query OK, 1 row affected (0.00 sec)
mysql>
  1. 사용자 계정 생성 (@는 자리 표시자, %는 모든 위치에서 로그인 허용)
mysql> create user 'jumpserver_user'@'%' IDENTIFIED BY 'dbuser2023';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>
  1. JumpServer 사용자에게 JumpServer 데이터베이스 접근 권한 부여
# 'jumpserver_user'@'%' 사용자가 'dbuser2023' 비밀번호로 jumpserver.* 모든 테이블에 대한 모든 권한(추가, 삭제, 수정, 조회)을 허용하도록 권한 부여
mysql> grant all privileges on jumpserver.* to 'jumpserver_user'@'%' identified by 'dbuser2023';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>exit
Bye

태그: MySQL CentOS rpm 데이터베이스 초기설정

6월 16일 22:09에 게시됨