Yebali

CentOS7에 Mysql 5.6 설치하기 본문

DB

CentOS7에 Mysql 5.6 설치하기

예발이 2021. 9. 21. 15:29

yum을 이용한 설치

설치 방법

# repository 추가
sudo rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

# 설치
sudo yum install mysql-community-server

 

Mysql 시작

# mysql 시작
sudo systemctl start mysqld

# mysql 상태 확인
sudo systemctl status mysqld

 

Mysql 설정

# mysql 접속, 처음에는 비밀번호가 없기 때문에 password입력 시 그냥 엔터치면 된다.
mysql -u root -p

# 'mysql' 데이터 베이스 사용.
# root 비밀번호를 바꾸는 것은 mysql DB의 user테이블의 정보를 바꾸는 것이다.
use mysql;

# 패스워드 변경, 예시에서는 yebali1234 로 했습니다.
update user set password = password('새로운패스워드') where user = 'root';

# 변경사항 적용
flush privileges;

 

mysql 콘솔을 나간 후 다시 root 계정으로 로그인할때 변경한 비밀번호로 로그인 할 수 있다.
해당 방법은 mysql5.6 까지만 가능하다. 5.7 이후 버전은 다른 방법으로 수정해야한다.

 

그 외 설정

mysql에 관한 다른 설정들을 /etc/my.cnf을 수정하여 변경 할 수 있다.

vi /etc/my.cnf

 

컴파일 설치

설치 전 할 일

mysql은 root 권한으로 실행하면 보안상 좋지 않고, 실행도 되지 않는다.
mysql을 실행할 mysql계정과 그룹을 만들어 주어야 한다.

groupadd mysql
useradd -M -g mysql mysql
cat /etc/passwd

 

그리고 설치에 필요한 종속성들을 설치해주어야 한다.

sudo yum -y install ncurses-devel
sudo yum -y install perl
sudo yum -y install perl-Data-Dumper
sudo yum -y install cmake
sudo yum -y install wget
sudo yum -y install gcc-c++

 

설치 파일 다운로드

# 설치를 원하는 특정 버전의 mysql 다운
sudo wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz

# 압축풀기
tar xvfz mysql-5.6.15.tar.gz

 

Mysql Configuration

# 해당 디렉토리로 이동
cd mysql-5.6.15

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
  • --prefix : Mysql을 설치 할 경로

설치

make -j 8 (스레드 8개를 사용해서 컴파일, pc사양에 따라 자유롭게 조절.)

# sudo 권한이 없을 경우 디렉토리를 만들지 못할 수 있음.
sudo make install

 

소켓이 생성될 디렉토리 생성

sudo mkdir /usr/local/mysql/tmp
sudo chown -R mysql:mysql /usr/local/mysql
sudo chown mysql:root /usr/local/mysql/tmp

mysql을 실행할 mysql경로의 소유권을 mysql사용자로 설정한다.
mysql 데몬을 뛰우기 전에 소켓 만드는 것을 root가 하기 때문에 tmp 디렉터리의 group 소유권은 root로 변경한다.

 

기본 데이터베이스 설치

sudo /usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/usr/local/mysql/my.cnf \
--user=root \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data \
--explicit_defaults_for_timestamp=on

 

설정 파일 추가

sudo vi /etc/my.cnf

아래 내용을 추가한다.

# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:

http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
port=3306
socket=/usr/local/mysql/tmp/mysql.sock
character-set=utf8

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
user=mysql
port=3306
socket=/usr/local/mysql/tmp/mysql.sock
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

character-set-server=utf8
collation-server=utf8_general_ci

init_connect=SET collation_connection=utf8_general_ci
init_connect=SET NAMES utf8

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
default-character-set = utf8
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

 

Mysql 실행

sudo /usr/local/mysql/bin/mysqld

# 실행 확인
ps -ef | grep mysql

 

이후 필요에 따라 service등록, mysql 환경변수 설정, root 비밀번호 변경 등의 작업을 하고 사용하면 된다.

'DB' 카테고리의 다른 글

[Database] Database의 Index  (0) 2022.11.20
Mysql Join  (0) 2021.09.21
Mysql DB 백업 및 복구  (0) 2021.09.21
Mysql 테이블 복사  (0) 2021.09.21
Mysql 계정 비밀번호 변경하기  (0) 2021.09.21