https://opensrc.tistory.com/191?category=475519현재 MySQL 8 버전이 올라와 있습니다. 작년 까지만 해도 5.x 대 였는데 어떻게 된 것인가... 싶었는데 아마도 5.8 버전 부터 MySQL 8 이라고 부르는 것 같습니다. 

MySQL이 Oracle에 인수되고나서 오픈소스 진영에서 동일한 클론으로 배포되던 Maria DB와도 5.6 후로는 완벽히 동일하다는 말이 사라진 것으로 보아 이후 버전은 소스코드가 별개로 가지 않나 싶은 생각이 드네요

아직은 MySQL 8버전에 대한 자료가 많지 않고 레퍼런스가 많지 않다고 판단되어 5.7버전을 선택하기로 했습니다.

실제로 설치 해보니 5.7버전도 시작부터 몇가지 기존 버전과 다른 점이 있어 몇번 삽질을 했습니다.

가장 문제가 된 점은 설치 root로 접속을 할 수 없는 점 이었습니다. rpm 패키지를 yum 으로 인스톨 하면서 비밀번호 설정하는 곳이 없는데 비밀번호를가 틀려서 접속 할 수가 없습니다.

공식문서(https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html) 에 살펴보니 설치되면서 관리자 계정 root@localhost 이 생성되고 임시 비밀번호는 /var/log/mysqld.log 에 기록된다고 하네요.

설치 후 

shell> sudo grep 'temporary password' /var/log/mysqld.log

명령으로 확인 가능하다고 합니다.

이점 참고 해서 MySQL 5.7 버전을 설치 하고 관리자 계정의 비번을 원하는대로 변경 하도록 하겠습니다.

그리고 마지막으로 비밀번호를 분실 했을 경우 기존 버전에서  mysqld-safe --skip-grant-tables 명령르로 실행 후 접속해서 비번을 변경하던 방식을 mysqld-safe 명령이 사라진 5.7 버전에서는 어떻게 하는지 알아보았습니다.


가장 먼저 설치할 패키지의 주소를 확인합니다.

CentOS 7은 Red Hat Enterparise Linux 7  과 동일한 오픈 버전입니다.

https://dev.mysql.com/downloads/repo/yum/

로그인 하지 않은 상태에서 다운로드를 클릭하면 로그인 하라고 창이 먼저 나옵니다.

Oracle 계정이 없으신 분은 하나 만들어 두시면 두고 두고 쓸일이 있을 것이니 하나 생성하시길... 공짠데 뭐 ㅋ

로그인을 완료 하면 아래 처럼 다운로드 화면으로 자동으로 이동합니다. 크롬에서 검사를 눌려 보면 실제 파일의 경로가 보입니다

현재 Red Hat 7(CentOS 7)용 MySQL 5.7의 패키지 경로는 /get/mysql57-community-release-el7-11.noarch.rpm 입니다.

이것을 도메인과 합치면 https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm 가 됩니다.


이것을 로컬에 다운 받아서 ftp로 서버에 올려서 설치해도 되고, 서버에서 wget 명령으로 직접 다운받아서 해도 되고 패키지의 경로로 위 주소를 직접 지정해서 설치도 가능합니다.

이번에는 세번째 방법으로 설치 하도록 하겠습니다.

root 권한으로 실행합니다.

[root@localhost ~]# rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

[root@localhost ~]# yum -y install mysql-community-server

mysql-community-server 를 설치함으로써 의존성이 걸려있는 mysql-community-server, mysql-community-client, mysql-community-libs, mysql-community-common 네개의 패키지가 설치 됩니다.


요즘은 대부분 케릭터셋이 utf-8로 통일 되고 있는 추세 입니다.

혹시 나중에 문제가 될 수 있으니 /etc/my.cnf 에 한줄 추가 하도록 하겠습니다.

[mysqld]

collation-server = utf8_unicode_ci

character-set-server = utf8

... 생략


설치 완료 후 데몬을 실행하도록 하겠습니다.

[root@localhost ~]# systemctl start mysqld


로그인 하기 전에 mysql이 설치되면서 입력된 임시 비밀번호를 확인해야 한다.

[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log

2018-02-13T14:49:45.720116Z 1 [Note] A temporary password is generated for root@localhost: tur++-dvf7tI

부여된 패스워드는 붉은 부분(실제로는 붉은 글씨가 아님)입니다.


임시 비번으로 로그인 해서 새로운 비밀번호를 부여하도록 하겠습니다.

[root@localhost ~]# mysql -u root -p

Enter password : tur++-dvf7tI

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.21


Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> use mysql

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


헐... 임시 비밀번호를 바꾸기 전에는 아무것도 할 수 없는 듯...


mysql> alter user 'root'@'localhost' identified by '새비밀번호';

Query OK, 0 rows affected (0.00 sec)


mysql> commit;

Query OK, 0 rows affected (0.00 sec)


mysql> quit

Bye



이제 비밀번호가 잘 바뀌었는지 확인 해보도록 하겠습니다.

[root@localhost download]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.21 MySQL Community Server (GPL)


Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed

mysql> show tables;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                        |

| engine_cost               |

| event                     |

| func                      |

| general_log               |

| gtid_executed             |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| innodb_index_stats        |

| innodb_table_stats        |

| ndb_binlog_index          |

| plugin                    |

| proc                      |

| procs_priv                |

| proxies_priv              |

| server_cost               |

| servers                   |

| slave_master_info         |

| slave_relay_log_info      |

| slave_worker_info         |

| slow_log                  |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

31 rows in set (0.00 sec)

mysql> quit

Bye


정상적으로 설치가 된것 같습니다.


끝으로 이전 버전에서 root 비밀번호를 분실 했을때 유용하게 이용되던 mysqld-safe 명령에 대해서 알아 보겠습니다.

MySQL 5.7버전을 설치 한 후에 저 명령을 아무리 찾아도 없었습니다. 구글링 끝에 

https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7

이런 내용의 글을 보았습니다.


간단히 요약해 보면

1. mysqld-safe  명령은 사라졌음

2. user 테이블의 구조가 바뀌었음

그래서 아래의 순서에 따라서 비밀번호를 바꿀 수 있습니다.

1. MySQL 서버 중지

[root@localhost ~]# systemctl stop mysqld

2. MySQL 환경변수 설정

[root@localhost ~]# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3. MySQL  서버 가동

[root@localhost ~]# systemctl start mysqld

4. 비번 없이  root 로그인

[root@localhost ~]# mysql -u root

5.  root 비밀번호 업데이트

mysql> UPDATE mysql.user SET authentication_string = PASSWORD('새비밀번호')

    -> WHERE User = 'root' AND Host = 'localhost';

mysql> FLUSH PRIVILEGES;

mysql> quit

6.  MySQL 중지

[root@localhost ~]# systemctl stop mysqld

7. MySQL 환경변수 초기화

[root@localhost ~]# systemctl unset-environment MYSQLD_OPTS

8. MySQL 서버 시작

[root@localhost ~]# systemctl start mysqld

9. 새 비밀번호로 로그인 확인

[root@localhost ~]# mysql -u root -p

참고로  user 테이블이 변경 된것은 user 테이블의 접근을 쿼리가 아닌 시스템 명령으로 하면 큰 차이는 없을 것 같습니다.

MySQL 홈페이지에서도 

alter user 'root'@'localhost' identified by '새비밀번호';

이런 형태를 권장 하는 것 같습니다.


이제 다음번에는 db를 생성하고 user 를 생성해서 공간을 할당해 보도록 하겠습니다.



MySQL DB 생성과 사용자 추가는 아래 링크의 [CentOS 7 minimal 설치] MySQL DB생성, User생성 편 를 참고 하세요

https://opensrc.tistory.com/191?category=475519

+ Recent posts