Database/설치
[MySQL] CentOS7 환경에 MySQL Database 설치하기
lv.COCO
2023. 3. 14. 17:58
1. MySQL 홈페이지 접속
https://www.mysql.com/products/community/
2. 'Download MySQL Community Edition' 클릭
3. yum 설치를 위해 Yum Repository 선택
4. CentOS7 파일 'Download'
5. 'No thanks, just start my download' 마우스 오른쪽 버튼 -> '링크 주소 복사'
6. (CentOS7 환경 / root 계정)
아래 yum~ command 입력으로 mysql 설치 진행
# yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
Loaded plugins: fastestmirror, langpacks
mysql80-community-release-el7-7.noarch.rpm | 11 kB 00:00:00
Examining /var/tmp/yum-root-QZHkdH/mysql80-community-release-el7-7.noarch.rpm: mysql80-community-release-el7-7.noarch
Marking /var/tmp/yum-root-QZHkdH/mysql80-community-release-el7-7.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql80-community-release.noarch 0:el7-7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================================================================================================
Installing:
mysql80-community-release noarch el7-7 /mysql80-community-release-el7-7.noarch 10 k
Transaction Summary
=============================================================================================================================================================================================================================================
Install 1 Package
Total size: 10 k
Installed size: 10 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql80-community-release-el7-7.noarch 1/1
Verifying : mysql80-community-release-el7-7.noarch 1/1
Installed:
mysql80-community-release.noarch 0:el7-7
Complete!
7. community 버전 Repository 설치 확인
# yum repolist enabled | grep "mysql.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 213
mysql-tools-community/x86_64 MySQL Tools Community 96
mysql80-community/x86_64 MySQL 8.0 Community Server 386
+ 진행 중 Trying other mirror. 에러 발생 시
# yum clean all로 캐시 지운 후 command 재입력
8. 설치 가능한 MySQL 패키지 목록 조회
# yum search mysql
.
.
.
9. MySQL 설치
[root@kim ~]# yum install -y mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.kakao.com
* epel: mirror-kr.misakamikoto.network
* extras: mirror.kakao.com
* updates: mirror.kakao.com
.
.
.
10. 설치 버전 확인
[root@kim ~]# mysqld -V
/usr/sbin/mysqld Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL)
[root@kim ~]# mysql --version
mysql Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL)
11. MySQL 구동
[root@kim ~]# systemctl enable mysqld
[root@kim ~]# systemctl start mysqld
[root@kim ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 목 2023-03-16 13:09:40 KST; 4s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 19037 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 19116 (mysqld)
Status: "Server is operational"
Tasks: 39
CGroup: /system.slice/mysqld.service
└─19116 /usr/sbin/mysqld
3월 16 13:09:36 kim systemd[1]: Starting MySQL Server...
3월 16 13:09:40 kim systemd[1]: Started MySQL Server.
+ 아래와 같은 에러 발생 시 https://coco-space.tistory.com/16 참고하여 + MariaDB가 사용 했던 모든 로그까지 제거 (기존에 설치되어 있던 MariaDB 관련 에러)
[root@kim ~]# systemctl enable mysqld && systemctl start mysqld && systemctl status mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
이후 MariaDB에서 생성한 데이터파일과 로그 파일이 없는 것 확인
[root@kim ~]# ls -al /var/lib/mysql
합계 4
drwxr-x--x. 2 mysql mysql 6 12월 17 02:22 .
drwxr-xr-x. 64 root root 4096 3월 16 13:04 ..
12. MySQL 초기 비밀번호 확인
[root@kim ~]# grep 'temporary password' /var/log/mysqld.log
13. MySQL 접속
[root@kim ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32
Copyright (c) 2000, 2023, 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>
14. 보안정책 조회 & 비밀번호 변경
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Abcdef1234!@';
Query OK, 0 rows affected (0.01 sec)
15. Database 조회
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
+
14-1. 비밀번호 정책 변경
더보기
명령어 | 설명 |
validate_password.mixed_case_count | 대소문자 필수 사용 |
validate_password.number_count | 숫자 필수 사용 |
validate_password.special_char_count | 특수문자 필수 사용 |
validate_password.length | 패스워드 길이 |
validate_password.policy | 패스워드 정책 레벨 . LOW는 위의 정책들을 비활성화 시킴 |
validate_password.check_user_name | 패스워드에 user id 사용 가능 여부 |
더보기
mysql> SET GLOBAL validate_password.policy=LOW;
Query OK, 0 rows affected (0.00 sec)
mysql> SET GLOBAL validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
[root@kim ~]# vi /etc/my.cnf
아래 내용 추가 작성
validate_password.policy = LOW
validate_password.length = 4
[root@kim ~]# systemctl restart mysqld
[root@kim ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'ark5815';
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@kim ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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>
[root@kim ~]# systemctl restart mysqld
[root@kim ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'ark5815';
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@kim ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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>