파일 다운로드
■ 해당 경로에서 version과 OS에 맞게 download받은 파일을 서버에 전송
다운로드 경로 https://downloads.mysql.com/archives/community/
MySQL :: Download MySQL Community Server (Archived Versions)
Please note that these are old versions. New releases will have recent bug fixes and features! To download the latest release of MySQL Community Server, please visit MySQL Downloads. MySQL open source software is provided under the GPL License.
downloads.mysql.com
[root@localhost ~]# wget
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# ll
합계 649804
-rw-------. 1 root root 1464 7월 11 2019 anaconda-ks.cfg
-rw-r--r--. 1 root root 1512 7월 11 2019 initial-setup-ks.cfg
-rw-r--r--. 1 root root 665389778 1월 10 06:41 mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 root root 6 8월 5 2019 공개
drwxr-xr-x. 2 root root 6 8월 5 2019 다운로드
drwxr-xr-x. 2 root root 6 8월 5 2019 문서
drwxr-xr-x. 2 root root 6 8월 5 2019 바탕화면
drwxr-xr-x. 2 root root 6 8월 5 2019 비디오
drwxr-xr-x. 2 root root 6 8월 5 2019 사진
drwxr-xr-x. 2 root root 6 8월 5 2019 서식
drwxr-xr-x. 2 root root 6 8월 5 2019 음악
■ 해당 파일 압축 해제
[root@localhost ~]# tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
mysql-5.7.34-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-5.7.34-linux-glibc2.12-x86_64/bin/myisamchk
mysql-5.7.34-linux-glibc2.12-x86_64/bin/myisamlog
mysql-5.7.34-linux-glibc2.12-x86_64/bin/myisampack
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql_client_test_embedded
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql_config_editor
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql_embedded
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql_install_db
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql_plugin
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql_secure_installation
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql_ssl_rsa_setup
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql_tzinfo_to_sql
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysql_upgrade
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqladmin
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqlbinlog
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqlcheck
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqldump
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqlimport
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqlpump
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqlshow
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqlslap
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqltest_embedded
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqlxtest
mysql-5.7.34-linux-glibc2.12-x86_64/bin/mysqld-debug
mysql-5.7.34-linux-glibc2.12-x86_64/lib/libmysqld-debug.a
...생략
■ 압축 해제한 basdir을 편의상 /mysql로 바꿔주었습니다.
[root@localhost ~]# mv mysql-5.7.34-linux-glibc2.12-x86_64 /mysql
■ 엔진 소유자 mysql로 변경
[root@localhost ~ ]# chown -R mysql.mysql /mysql
■ group과 user 생성 (해당 그룹에 속한 mysql유저 생성)
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
Config 수정
■ my.cnf 파일 수정 (mysql 파라미터 파일)
[root@localhost ~]# vi /etc/my.cnf
[mysqld]
datadir=/data // 데이터 떨굴곳 지정
socket=/tmp/mysql.sock // 소캣 저장할곳 지정
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
log-error=/log/mariadb.log // 로그 떨굴곳 지정
pid-file=/log/mariadb.pid // pid 저장할 곳 지정
[mysqld_safe]
log-error=/log/mariadb.log
pid-file=/log/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
■ datadir 과 logdir 생성 및 소유자 변경
[root@localhost ~]# mkdir /data /log
[root@localhost ~]# chown mysql.mysql /data /log
■ bash_profile 경로 수정
[root@localhost ~]# vi ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/mysql/bin
export PATH
## config 동기화
[root@localhost ~]# source ~/.bash_profile
■ mysql DB실행
[root@localhost ~]# mysqld --initialize --user=mysql //5.7버전 이상부터는 initlize를 해줘야합니다. 이전 버전에서는 install 스크립트 이용해서 설치했습니다!!
[root@localhost ~]# mysqld_safe --user=mysql --basedir=/mysql & //backgroud로 실행
[1] 9573
[root@localhost ~]# 2022-01-09T22:14:28.781757Z mysqld_safe Logging to '/log/mariadb.log'.
2022-01-09T22:14:28.835000Z mysqld_safe Starting mysqld daemon with databases from /data
■ 프로세스 확인
[root@localhost ~]# ps -ef | grep mysql
root 9573 7324 0 07:14 pts/0 00:00:00 /bin/sh /mysql/bin/mysqld_safe --user=mysql --basedir=/mysql
mysql 9746 9573 0 07:14 pts/0 00:00:00 /mysql/bin/mysqld --basedir=/mysql --datadir=/data --plugin-dir=/mysql/lib/plugin --user=mysql --log-error=/log/mariadb.log --pid-file=/log/mariadb.pid --socket=/tmp/mysql.sock
root 9802 7324 0 07:15 pts/0 00:00:00 grep --color=auto mysql
■ 초기 비밀번호 확인
[root@localhost ~]# cat /log/mariadb.log | grep temp
2022-01-09T22:13:54.878030Z 1 [Note] A temporary password is generated for root@localhost: iy;<Rgar5Vi,
2022-01-09T22:14:29.053749Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
■ DB접속
[root@localhost ~]# mysql -uroot -p
Enter password: <초기 비밀번호 입력>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34
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>
■ 첫 접속 후 root유저의 패스워드 변경
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)
systemctl 등록 방법
systemctl은 필수적으로 등록 안해도 됩니다 하지만 mysqladmin으로 db내리고 올리기 귀찮으신 분들을 위해 필요하신 분들만 하시면 됩니다~
■ datadir과 basedir 경로 확인
mysql> select @@basedir;
+-----------+
| @@basedir |
+-----------+
| /mysql/ |
+-----------+
1 row in set (0.00 sec)
mysql> select @@datadir;
+-----------+
| @@datadir |
+-----------+
| /data/ |
+-----------+
1 row in set (0.00 sec)
■ 다시 basedir로 가면 support-files가 있습니다.
[root@localhost ~]# cd /mysql/
[root@localhost mysql]# ll
합계 268
-rw-r--r--. 1 mysql mysql 257591 3월 26 2021 LICENSE
-rw-r--r--. 1 mysql mysql 566 3월 26 2021 README
drwxr-xr-x. 2 mysql mysql 4096 1월 10 07:12 bin
drwxr-xr-x. 2 mysql mysql 55 1월 10 07:12 docs
drwxr-xr-x. 3 mysql mysql 4096 1월 10 07:12 include
drwxr-xr-x. 5 mysql mysql 230 1월 10 07:12 lib
drwxr-xr-x. 4 mysql mysql 30 1월 10 07:12 man
drwxr-xr-x. 28 mysql mysql 4096 1월 10 07:12 share
drwxr-xr-x. 2 mysql mysql 90 1월 10 07:12 support-files
■ support-files의 mysql.server 파일을 /etc/initd에 복사합니다.
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# ll
합계 24
-rw-r--r--. 1 mysql mysql 773 3월 26 2021 magic
-rwxr-xr-x. 1 mysql mysql 894 3월 26 2021 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 3월 26 2021 mysql.server
-rwxr-xr-x. 1 mysql mysql 1061 3월 26 2021 mysqld_multi.server
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
■ 복사한 파일 config 수정
[root@localhost support-files]# vi /etc/init.d/mysqld
# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
# [mysqld]
# basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
# and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
# below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/mysql
datadir=/data
# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900
# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
■ 수정된 내용을 반영하기 위해 daemon을 reload 해줍니다.
[root@localhost ~]# systemctl daemon-reload
■ DB shutdown 후 systemctl로 start합니다.
[root@localhost ~]# mysqladmin -uroot -proot shutdown
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
2022-01-10T01:45:30.494062Z mysqld_safe mysqld from pid file /log/mariadb.pid ended
[1]+ Done mysqld_safe --user=mysql --basedir=/mysql
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: active (running) since 월 2022-01-10 10:45:51 KST; 4s ago
Docs: man:systemd-sysv-generator(8)
Process: 10745 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
Tasks: 28
CGroup: /system.slice/mysqld.service
├─10755 /bin/sh /mysql/bin/mysqld_safe --datadir=/data --pid-file=/log/mariadb.pid
└─10931 /mysql/bin/mysqld --basedir=/mysql --datadir=/data --plugin-dir=/mysql/lib/plugin --user=mysql --log-error=/log/mariadb.log --pid-file=/log/mariadb.pid --socket=/tmp/m...
1월 10 10:45:50 localhost.localdomain systemd[1]: Starting LSB: start and stop MySQL...
1월 10 10:45:51 localhost.localdomain mysqld[10745]: Starting MySQL. SUCCESS!
1월 10 10:45:51 localhost.localdomain systemd[1]: Started LSB: start and stop MySQL.
■ db process 확인
[root@localhost ~]# ps -ef | grep mysqld
root 10755 1 0 10:45 ? 00:00:00 /bin/sh /mysql/bin/mysqld_safe --datadir=/data --pid-file=/log/mariadb.pid
mysql 10931 10755 1 10:45 ? 00:00:00 /mysql/bin/mysqld --basedir=/mysql --datadir=/data --plugin-dir=/mysql/lib/plugin --user=mysql --log-error=/log/mariadb.log --pid-file=/log/mariadb.pid --socket=/tmp/mysql.sock
root 10979 7324 0 10:46 pts/0 00:00:00 grep --color=auto mysqld
'DataBase > MySQL & MariaDB' 카테고리의 다른 글
[MariaDB - Galera Cluster & Maxscale 구성 및 failover test] part 2 (0) | 2022.02.24 |
---|---|
[MariaDB - Galera Cluster 구성] part 1 (0) | 2022.02.24 |
[MySQL - MHA 구성 + failover/switchover] part 2 (0) | 2022.01.28 |
[MySQL - MHA 구성 + VIP생성] part 1 (2) | 2022.01.28 |
[MariaDB 10.1 to 10.2 Upgrade] (0) | 2022.01.14 |