Ubunut에서 MySQL 8을 바이너리 파일로 설치하는 방법
테스트 환경
$ lsb_release -d
Description: Ubuntu 22.04.1 LTS
MySQL 설치
MySQL 바이너리 파일 다운로드
☞ MySQL Community Downloads
- https://dev.mysql.com/downloads/mysql
1. MySQL 계정 생성
** ubuntu sudo 그룹에서 group id 27번을 사용하고 있음.
Ubuntu 패키지 매니저를 사용하여 MySQL을 설치할 때, mysql 계정 정보
$ cat /etc/passwd | grep mysql
mysql:x:118:121:MySQL Server,,,:/nonexistent:/bin/false
$ cat /etc/group | grep mysql
mysql:x:121:
$ cat /etc/passwd | grep mysql
mysql:x:118:121:MySQL Server,,,:/nonexistent:/bin/false
---
groupadd -g 28 mysql
useradd -m -c "MySQL Server" -d /usr/local/mysql -s /bin/false -u 28 -g 28 mysql
- 생성된 mysql 계정 확인
cat /etc/passwd | grep mysql
$ cat /etc/passwd | grep mysql
mysql:x:28:28:MySQL Server:/usr/local/mysql:/bin/false
2. 작업 디렉토리로 이동(WORKDIR)
cd /usr/local/src
3. MySQL 바이너리 파일 다운로드
wget -q https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.31-linux-glibc2.12-x86_64.tar
$ ls -l mysql-8.0.31-linux-glibc2.12-x86_64.tar
-rw-r--r-- 1 root root 899880960 Sep 14 15:03 mysql-8.0.31-linux-glibc2.12-x86_64.tar
4. MySQL 바이너리 파일 압축 해제
tar xvf mysql-8.0.31-linux-glibc2.12-x86_64.tar
$ tar xvf mysql-8.0.31-linux-glibc2.12-x86_64.tar
mysql-test-8.0.31-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
mysql-router-8.0.31-linux-glibc2.12-x86_64.tar.xz
⊙ MySQL 바이너리 설치 파일 압축 해제
--strip-components=1 : /mysql/local/mysql/
tar xf mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz -C /usr/local/mysql/ --strip-components=1
$ ls -l /usr/local/mysql/
total 316
drwxr-xr-x 2 7161 31415 4096 Sep 14 05:08 bin
drwxr-xr-x 2 7161 31415 4096 Sep 14 05:08 docs
drwxr-xr-x 3 7161 31415 4096 Sep 14 05:08 include
drwxr-xr-x 6 7161 31415 4096 Sep 14 05:08 lib
-rw-r--r-- 1 7161 31415 287627 Sep 14 01:15 LICENSE
drwxr-xr-x 4 7161 31415 4096 Sep 14 05:08 man
-rw-r--r-- 1 7161 31415 666 Sep 14 01:15 README
drwxr-xr-x 28 7161 31415 4096 Sep 14 05:08 share
drwxr-xr-x 2 7161 31415 4096 Sep 14 05:08 support-files
5. MySQL 디렉토리 소유권 변경
chown -R mysql.mysql /usr/local/mysql
6. MySQL 설치 위치로 이동
cd /usr/local/mysql/
- MySQL 버전 확인
./bin/mysqld --version
$ ./bin/mysqld --version
/usr/local/mysql/bin/mysqld Ver 8.0.31 for Linux on x86_64 (MySQL Community Server - GPL)
7. 데이터베이스(DB) 데이터 디렉토리 생성
mkdir -p /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql/data
chmod 750 /usr/local/mysql/data
8. MySQL 환경 설정 파일 설정(edit my.cnf)
vim /usr/local/mysql/my.cnf
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
log-error=/usr/local/mysql/data/mysql_error.log
mysqlx=OFF
[client]
port = 3306
socket = /tmp/mysql.sock
9. 초기화 데이터베이스(DB) 설정
--initialize : 기본 데이터베이스 생성, 임의의 패스워드로 root 계정을 생성 (패스워드는 로그에서 확인)
--initialize-insecure : 기본 데이터베이스 생성, 빈 암호로 root 계정 생성
./bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize --user=mysql
10. MySQL root 패스워드 확인
cat /usr/local/mysql/data/mysql_error.log | grep "A temporary password is generated for root@localhost"
$ cat /usr/local/mysql/data/mysql_error.log | grep "A temporary password is generated for root@localhost"
2023-01-09T11:32:55.982985Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >beafXp!i67m
11. MySQL 서비스 실행
./bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
12. MySQL 접속 및 비밀번호 설정
MySQL 클라이언트 오류
- error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
$ ./mysql -uroot -p'>beafXp!i67m'
./mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
libncurses5 패키지 설치
apt-get install -y libncurses5
---
mysql -uroot -p'>beafXp!i67m'
$ ./mysql -uroot -p'>beafXp!i67m'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.31
Copyright (c) 2000, 2022, 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>
13. 초기 비밀번호 설정 및 보안 설정
ALTER USER 'root'@'localhost' IDENTIFIED BY '새로운_비밀번호';
14. MySQL 초기 보안 설정 수행
bin/mysql_secure_installation
15. 환경 변수 설정(PATH 설정)
vim ~/.bashrc
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
source ~/.bashrc
또는
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.bashrc
source ~/.bashrc
참고URL
- Server System Variable Reference : https://dev.mysql.com/doc/refman/8.0/en/server-system-variable-reference.html
- MySQL Configuration Utility : https://dev.mysql.com/doc/refman/8.0/en/mysql-config-editor.html
- Initializing the Data Directory : https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html
'리눅스' 카테고리의 다른 글
Ubuntu에 Node.js와 npm을 설치하는 방법 (0) | 2023.01.10 |
---|---|
apt(dpkg) error (0) | 2023.01.09 |
GNU C 라이브러리(glibc)의 버전을 확인하는 방법 (0) | 2023.01.09 |
CentOS 7에서 MySQL 8을 바이너리 파일로 설치하는 방법 (0) | 2023.01.09 |
Rocky Linux 9에서 Postfix 메일 서버를 설치하고 설정하는 방법 (0) | 2023.01.07 |