티스토리 뷰

리눅스

CentOS에 MySQL 설치

토마's 2018. 2. 10. 12:32

안녕하세요. 오늘은 리눅스(CentOS)에 MySQL을 설치하는 방법에 대해서 포스팅하려고 합니다.


우선, 기존과 같이 root 계정으로 centos에 접속을 합니다.



1. yum repository package 다운로드

wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm  명령어를 사용해서 패키지를 다운로드 받습니다.


2. Package 설치

yum localinstall mysql57-community-release-el7-11.noarch.rpm 명령어를 이용해서 다운로드 받은 패키지를 설치합니다.


3. MySQL yum repository 활성화

yum repolist enabled | grep "mysql.*-community.*" 명령어를 사용해 repository를 활성화 시키면 아래와 같은 화면을 확인할 수 있습니다.



그럼 본격적으로 MySQL의 설치를 진행합니다.


4. MySQL 설치

yum install mysql-community-server mysql mysql-libs mysql-devel mysql-server 명령어를 사용해 MySQL을 설치합니다.


5. MySQL 시작

systemctl start mysqld.service 명령어를 사용해 mysql을 시작합니다.

systemctl status mysqld.service 명령어를 사용해 현재 상태를 확인할 수 있습니다.



6. MySQL 부팅시 등록

systemctl enable mysqld.service 명령어를 사용해서 부팅시 mysql이 자동 실행되도록 설정합니다.


7. 패키지 설치시 root 패스워드가 임의로 설치되기 때문에 해당 임시 패스워드는

 /var/log/mysqld.log에 저장되어 있습니다.

grep 'temporary password' /var/log/mysqld.log 명령어를 사용해서 임시 패스워드를 확인합니다.



위와 같이 본인의 패스워드를 확인할 수 있습니다.


8. Secure 환경설정

mysql_secure_installation 명령어를 사용해서 본인에게 맞는 Secure 환경 설정을 해줍니다. 아래와 같이 질문들이 나오면 아래를 참조해서 패스워드 변경 및 각종 여부를 물어보는 것을 진행하시면 됩니다.


Securing the MySQL server deployment. 

 

Enter password for user root:  

 

The existing password for the user account root has expired. Please set a new password. 

 

New password:  

 

Re-enter new password:  

 ... Failed! Error: Your password does not satisfy the current policy requirements 

 

New password:  

 

Re-enter new password:  

The 'validate_password' plugin is installed on the server. 

The subsequent steps will run with the existing configuration 

of the plugin. 

Using existing password for root. 

 

Estimated strength of the password: 100  

Change the password for root ? ((Press y|Y for Yes, any other key for No) : n 

 

 ... skipping. 

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 

 

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!  


위의 절차대로 진행하면 All done 메시지가 출력되면서 완료된 것을 확인할 수 있습니다.


9. my.cnf 수정

vi /etc/my.cnf 명령어를 사용해서 수정을 하는데 아래의 내용 중에서 필요한 것들만 입력하거나 수정해주면 됩니다.


[client]  
default-character-set = utf8 
  

[mysql] 
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 
  

[mysqldump] 
default-character-set=utf8 


10. 포트 열어주기

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --reload


위의 두 명령어를 사용해서 포트를 열어줍니다.


11. 접속

mysql -u root -p 명령어를 사용해서 mysql에 접속을 시도하면, 각자가 설정한 패스워드를 입력하라는 입력란이 나오고 패스워드를 입력하면 다음과 같이 mysql에 접속한 화면을 확인할 수 있습니다.




12. 외부 접속 허용

mysql> use mysql         >> mysql 디비 선택 

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '패스워드' WITH GRANT OPTION; 

mysql> GRANT TRIGGER ON *.* TO 'root'@'%' WITH GRANT OPTION; 

mysql> GRANT SUPER ON *.* TO 'root'@'%'; 

mysql> FLUSH PRIVILEGES; 


위의 명령어를 사용해서 외부 접속을 허용할 수 있습니다.


13. MySQL 상태 보기

status 명령어를 사용해서 MySQL의 상태를 확인할 수 있습니다.



이것으로 CentOS에서 MySQL을 설치하는 방법에 대한 포스팅을 마치도록 하겠습니다. : )