Database
[Database] Rocky Linux에 MariaDB 설치 방법
cloud-grace
2024. 5. 16. 14:35
Rocky Linux9에 MariaDB 설치하는 방법에 대해 알아보자.
[1] MariaDB 설치
1. 작업 디렉토리 확인
# pwd
/root
2. 의존 라이브러리 설치
# dnf install -y gcc gcc-c++ zlib* libxml* freetype* libpng* flex gmp ncurses-devel gnutls-devel libaio
3. iconv 소스 컴파일 설치
# wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz
# tar xvfz libiconv-1.17.tar.gz
# cd libiconv-1.17
# ./configure --prefix=/usr/local
# make && make install
4. 소스 다운로드
# wget https://downloads.mariadb.org/interstitial/mariadb-10.6.17/source/mariadb-10.6.17.tar.gz
5. 압축 풀기
# tar xvfz mariadb-10.6.17.tar.gz
6. 소스 디렉토리 이동
# cd mariadb-10.6.17
7. 빌드 환경 설정
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/cloud/mariadb -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DMYSQL_DATADIR=/usr/local/cloud/mariadb/data -DMYSQL_UNIX_ADDR=/usr/local/cloud/mariadb/tmp/mariadb.sock -DINSTALL_SYSCONFDIR=/usr/local/cloud/mariadb/etc -DINSTALL_SYSCONF2DIR=/usr/local/cloud/mariadb/etc/my.cnf.d -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_ARIA_STORAGE_ENGINE=1 -DWITH_XTRADB_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATEDX_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=bundled -DWITH_ZLIB=system
8. 빌드 & 설치
# make && make install
[2] MariaDB 설정
1. 설정 작업을 위해 root 홈 디렉토리로 이동
# cd
# pwd
/root
2. 실행 계정 생성
# groupadd mysql
# useradd -M -g mysql mysql
3. MariaDB 설치 디렉토리 소유자 변경
# chown -R mysql:mysql /usr/local/cloud/mariadb
4. 설정 파일 위치 변경
cp -R /usr/local/cloud/mariadb/etc/my.cnf.d /etc
5. 기본(관리) 데이터베이스(mysql) 생성
# /usr/local/cloud/mariadb/scripts/mysql_install_db --user=mysql --basedir=/usr/local/cloud/mariadb --defaults-file=/usr/local/cloud/mariadb/etc/my.cnf --datadir=/usr/local/cloud/mariadb/data
6. 서버 구동
# /usr/local/cloud/mariadb/bin/mysqld_safe &
7. root 패스워드 설정
# /usr/local/cloud/mariadb/bin/mysqladmin -u root password '........'
8. 데이터베이스 접속 테스트
# /usr/local/cloud/mariadb/bin/mysql -u root -p
9. path 설정(/etc/profile)
# mysql
export PATH=$PATH:/usr/local/cloud/mariadb/bin
10. 서버 강제 종료
# ps -ef | grep mysql
root 865 1 0 16:23 ? 00:00:00 /bin/sh /usr/local/cloud/mariadb/bin/mysqld_safe --datadir=/usr/local/cloud/mariadb/data --pid-file=/usr/local/cloud/mariadb/data/lx.cloud.me.pid
mysql 968 865 0 16:23 ? 00:00:00 /usr/local/cloud/mariadb/bin/mysqld --basedir=/usr/local/cloud/mariadb --datadir=/usr/local/cloud/mariadb/data --plugin-dir=/usr/local/cloud/mariadb/lib/plugin --user=mysql --log-error=/usr/local/cloud/mariadb/data/lx.cloud.me.err --pid-file=/usr/local/cloud/mariadb/data/lx.cloud.me.pid
# kill -9 865 968
# ps -ef | grep mysql
[3] 서비스 데몬 등록
1. MariaDB systemd service script (/usr/lib/systemd/system/mariadb.service)
#
# mariadb systemd service file
#
[Unit]
Description=MariaDB 10.6.11 Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=mariadb.service
[Service]
User=mysql
Group=mysql
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Needed to create system tables etc.
# ExecStartPre=/usr/bin/mysql-systemd-start pre
# Start main service
ExecStart=/usr/local/poscodx/mariadb/bin/mysqld_safe
# Don't signal startup success before a ping works
# ExecStartPost=/usr/bin/mysql-systemd-start post
# Give up if ping don't get an answer
TimeoutSec=600
Restart=always
PrivateTmp=false
2. 서비스(데몬, Daemon) 등록/시작/중지
# systemctl enable mariadb.service
# systemctl start mariadb
# ps -ef | grep mysql
3. 재부팅 후, mysql 클라이언트로 접속 테스트
# mysql -u root -p
password:
MariaDB [(none)]>
[4] 데이터베이스 생성 및 사용자 인증/권한 부여
1. DBA(DB 관리자) 권한으로 접속
# mysql -p;
2. webdb database 생성
MariaDB [none]> create database webdb;
3. local 접속 계정 webdb 생성
MariaDB [none]> create user 'webdb'@&'localhost' identified by 'webdb';
MariaDB [none]> grant all privileges on webdb.* to 'webdb'@'localhost';
MariaDB [none]> flush privileges;
4. 테스트
# mysql -u webdb -D webdb -p
5. 특정 IP(ex. windows 192.168.00.00)의 접속 계정 webdb 생성
MariaDB [none]> create user 'webdb'@'192.168.00.00' identified by 'webdb';
MariaDB [none]> grant all privileges on webdb.* to 'webdb'@'192.168.00.00';
MariaDB [none]> flush privileges;
6. MySQL Workbench로 연결 테스트