본문 바로가기

IT/Linux

[Linux] CentOS 7 Mysql 설치

1. MySql 5.7 설치

yum -y install http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql-community-server

위 두개의 파일을 다운로드 합니다.

mysql을 실행하면 임시 비밀번호가 생성되고 mysqld.log 파일 안에서 임시 비밀번호를 확인 할 수 있습니다.

systemctl start mysqld

vi
/var/log/mysqld.log

임시 비밀번호는 MYk+*FL?c2pu와 같이 생성된다.

mysql -u root -p

mysql을 실행하고, root계정으로 로그인합니다.

로그인이 완료되면, 비밀번호를 재설정 합니다.

ALTER USER 'root'@'localhost' IDENTIFIED BY '!@#QWEasd123';
FLUSH PRIVILEGES;

비밀번호 보안수준을 높게 해야하기 때문에, 특수문자, 영대소문자, 숫자를 모두 입력해야합니다.

status 명령어를 입력하면 설치된 Mysql 정보를 볼 수 있습니다.

2. CharacterSet UTF8 설정하기

mysql의 기본 charset은 latin1입니다. 이것을 utf8로 바꾸어 보겠습니다.

mysql 설정은 my.cnf 파일에서 변경할 수 있습니다. 

vi /etc/my.cnf 

위 명령어를 입력해 my.cnf 파일을 열고 다음과 같이 수정해줍니다.

[client]
default-character-set = utf8

[mysql]
default-character-set=utf8

[mysqldump]
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

character-set-server=utf8
collation-server=utf8_general_ci
init_connect=SET collation_connection = utf8_general_ci
init_connect=SET NAMES utf8

character-set-client-handshake = FALSE
skip-character-set-client-handshake

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

 

설정이 완료되었다면, Mysql을 재시작하고 다시 접속합니다.

systemctl restart mysqld

mysql -u root -p

status

status 명령어로 확인하면 모든 charset이 utf8로 변경된 것을 볼 수 있습니다.

mysql status

이 것으로 포스팅을 마치겠습니다.

 

참조 - https://www.opentutorials.org/module/1701/10229

 

Centos 7 - 데이타베이스(MySql) 설치 - 나만의 Web Server 만들기

Centos7 부터는 데이타베이스가 Mariadb로 바뀌었습니다. 그래서 MySql을 yum 으로 바로 설치가 불가능합니다. 때문에 아래 명령을 차례로 입력하여 줍니다. # yum -y install http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm # yum -y install mysql-community-server # systemctl start mysqld # systemct

www.opentutorials.org