본문 바로가기

프로그래밍

최신 MySQL 설치 및 접속, 초기 패스워드 설정

CentOS 기준입니다.

7, 8 버전에 맞춰서 아래 파일을 다운로드 한다.

 

CentOS 7

# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

 

CentOS 8

# wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

 

다운로드 받은 rpm 설치

# rpm -Uvh mysql80-community-release-el7-3.noarch.rpm 

혹은

# rpm -Uvh mysql80-community-release-el8-1.noarch.rpm

 

/etc/yum.repos.d/mysql-community.repo 수정

[mysql80-community] 항목의 enabled=0 => 1로 변경

 

mysql rpm 설치

# yum install mysql mysql-server

 

mysql-server 데몬 실행

# systemctl start mysqld

 

 

초기 임시 패스워드 확인 (A temporary password 부분)

# cat /var/log/mysqld.log

----------

2021-02-08T07:31:22.142319Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.23) initializing of server in progress as process 19733

2021-02-08T07:31:22.206205Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.

2021-02-08T07:31:24.576335Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.

2021-02-08T07:31:26.250719Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /49LtfcKqNOu

2021-02-08T07:31:29.735853Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.23) starting as process 19795

2021-02-08T07:31:29.769227Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.

2021-02-08T07:31:30.379689Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.

2021-02-08T07:31:30.546393Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock

2021-02-08T07:31:30.828315Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.

2021-02-08T07:31:30.828558Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.

2021-02-08T07:31:30.860183Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.23'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.

-------------

 

로컬에서 접속

# mysql -uroot -p [엔터]

Enter password: [위의 초기 패스워드 입력]

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

Your MySQL connection id is 8

Server version: 8.0.23

 

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

 

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>

 

패스워드 변경

mysql> alter user 'root'@'localhost' identified with mysql_native_password by '변경할패스워드';

Query OK, 0 rows affected (0.07 sec)

 

[추가로 외부에서 접속 허용할 때]

mysql> use mysql;

mysql> update user set host='%' where user='root';

Query OK, 1 row affected (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 0

 

변경된 권한 적용

mysql> flush privileges;

 

 

이제 변경된 패스워드로 로컬 혹은 외부에서도 접속할 있습니다.