본문 바로가기

Database/MySQL

CentOS 7.6버전에 MySQL 8.0 버전 설치

[환경]

homedb : 10.100.10.11

 
-- 접속
ssh admin@10.100.10.11
예시: admin / 암호, 나중에 변경 


-- 리눅스 버전확인 
shell> cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)  

 

MySQL rpm   최신 버전 확인
https://dev.mysql.com/downloads/repo/yum/

 

MySQL :: Download MySQL Yum Repository

Support EOL for Fedora 37 Per the MySQL Support Lifecycle policy regarding ending support for OS versions that have reached end of life, we plan to discontinue building all MySQL binaries for the Fedora 37 platform as of Dec 5, 2023. See Fedora 37 End of L

dev.mysql.com

  

인터넷 연결 확인(네트워크 담당자에게 요청) 

다운로드하려는 버전의 파일주소를 복사해서 wget로 다운로드
shell> wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm 

shell> sudo yum localinstall mysql80-community-release-el7-3.noarch.rpm 

 


--다른 버전과  충돌 시 확인 
shell> yum install mysql-community-release 

-- 다른 버전 설치되어있다면 삭제 
shell> rpm -e --nodeps mysql-community-release-el7-5.noarch 

  

shell> sudo yum repolist enabled | grep "mysql.*-community.*" 
mysql-connectors-community/x86_64       MySQL Connectors Community           153 
mysql-tools-community/x86_64            MySQL Tools Community                110 
mysql80-community/x86_64                MySQL 8.0 Community Server           177 

shell> sudo yum install mysql-community-server mysql mysql-libs mysql-devel mysql-server  

 

 

shell> sudo service mysqld start 
Redirecting to /bin/systemctl start mysqld.service 

shell> sudo service mysqld status 
Redirecting to /bin/systemctl status mysqld.service 
● mysqld.service - MySQL Server 
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) 
Active: active (running) since Wed 2020-02-19 16:57:50 KST; 52s ago 
    Docs: man:mysqld(8) 
           http://dev.mysql.com/doc/refman/en/using-systemd.html 
  Process: 2273 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) 
 Main PID: 2354 (mysqld) 
   Status: "Server is operational" 
   CGroup: /system.slice/mysqld.service 
           └─2354 /usr/sbin/mysqld 

 

-- 시스템 시작시 자동실행 등록 
shell> systemctl enable mysqld.service 

 

shell>  sudo service mysqld start 
Redirecting to /bin/systemctl start mysqld.service 

 

shell> systemctl enable mysqld.service 
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files === 
Authentication is required to manage system service or unit files. 
Multiple identities can be used for authentication: 
 1.  Cloud User (centos) 
 2.  jlee 

 

 

shell> sudo grep 'temporary password' /var/log/mysqld.log 
2020-02-19T07:57:46.536467Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 9K7z?X-2<7=Z 

 -- root 계정으로 접속 암호는 위에 임시 암호를 사용
shell>  mysql -uroot -p 

   

-- 암호 변경 예시  
ALTER USER 'root'@'localhost' IDENTIFIED BY 'ADFASmysqladmin!@#$111'; 

 --  my.cnf 파일 위치 찾기 
shell>  mysqld --verbose --help | grep -A 1 'Default options' 
Default options are read from the following files in the given order: 
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf  

 -- 데이터파일 경로 변경 
mysql> select @@datadir; 

+-----------------+ 
| @@datadir       | 
+-----------------+ 
| /var/lib/mysql/ | 

 

-- /data/mysql 폴더로 지정할 경우

shell> cd /data
shell>  sudo mkdir mysql 

shell> sudo rsync -av /var/lib/mysql /data/ 
shell> sudo chown -R mysql:mysql /data/mysql 

 

-- my.cnf 파일의 경로 수정 
shell>   sudo vi /etc/my.cnf 

[mysqld] 
datadir=/data/mysql 
socket=/data/mysql/mysql.sock 

 
[client] 
socket=/data/mysql/mysql.sock 

#symbolic-links=0 
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

 
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin 

 default-authentication-plugin=mysql_native_password 

 

-- SELinux 보안 context에 추가 및 서비스 시작 
-- 아래와 같은 명령어로 SELinux 보안 context에 적용을 시키고 서비스를 시작한다. 

shell> sudo semanage fcontext -a -t mysqld_db_t "/data/mysql(/.*)?" 
shell>  sudo restorecon -R /data/mysql 
shell>  sudo systemctl start mysqld 

 
-- DB 경로 확인 
mysql> select @@datadir; 

+--------------+ 
| @@datadir    | 
+--------------+ 
| /data/mysql/ | 
+--------------+ 

1 row in set (0.00 sec) 

 

 

--DB 홈디렉토리 변경 후에 정책 변경
 -- 암호 정책 변경 
SHOW VARIABLES LIKE 'validate_password%'; 
set global 변수 = 값; 
 
set global validate_password.mixed_case_count = 0; 
set global validate_password.number_count = 0; 

-- 패스워드 변경 
ALTER USER 'root'@'localhost' IDENTIFIED BY '암호'; 
FLUSH privileges; 

  

-- 계정 확인 후 생성  
use mysql; 
select host, user from user; 

 

create user 'user1'@'%' identified by 'user1암호';  
CREATE DATABASE db1 default CHARACTER SET UTF8;  
grant all privileges on db1.* to user1@'%';