Server setting 3

데이터베이스 설정

Posted by ETHAN KIM on July 13, 2022 · 4 mins read
Server PHP

root 계정 혹은 sudo 권한 계정으로 진행


1. MariaDB 초기설정

  • 보안설정 명령
  • root 비밀번호 초기설정 부분 제외하고 전부 Enter 패스하여도 무방
    [root@centos7 ~]# sudo mysql_secure_installation
    Set root password? [Y/n] y
    New password:
    Re-enter new password:
    Password updated successfully!
    ...
    
  • sql접속
    [root@centos7 ~]# mysql -u root -p
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 17
    Server version: 5.5.68-MariaDB MariaDB Server
    
  • 현재 데이터베이스 확인 및 사용할 DB생성
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.00 sec)
    MariaDB [(none)]> CREATE DATABASE testDB;
    Query OK, 1 row affected (0.00 sec)
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | testDB             |
    | mysql              |
    | performance_schema |
    +--------------------+
    
  • 로컬 및 와일드카드(특정ip만 허용하여도 무방) 호스트 유저 생성
    MariaDB [(none)]> user mysql;
    Database changed
    MariaDB [mysql]> select host,user,password from user;
    +-----------------------+----------+-------------------------------------------+
    | host                  | user     | password                                  |
    +-----------------------+----------+-------------------------------------------+
    | localhost             | root     | *passwd                                   |
    | 127.0.0.1             | root     | *passwd                                   |
    | ::1                   | root     | *passwd                                   |
    +-----------------------+----------+-------------------------------------------+
    3 rows in set (0.00 sec)
    MariaDB [mysql]> create user 'testUSER'@'localhost' IDENTIFIED BY '1234'; /*로컬접속 유저 생성*/
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [mysql]> create user 'testUSER'@'%' IDENTIFIED BY '1234'; /*와일드카드 ip 접속 유저 생성*/
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [mysql]> select host,user,password from user;
    +-----------------------+----------+-------------------------------------------+ /*생성한 유저 확인*/
    | host                  | user     | password                                  |
    +-----------------------+----------+-------------------------------------------+
    | localhost             | root     | *passwd                                   |
    | 127.0.0.1             | root     | *passwd                                   |
    | ::1                   | root     | *passwd                                   |
    | localhost             | testUSER | *passwd                                   |
    | %                     | testUSER | *passwd                                   |
    +-----------------------+----------+-------------------------------------------+
    5 rows in set (0.00 sec)
    
  • 생성한 유저에게 사용DB 권한 부여
    MariaDB [mysql]> grant all previleges on fairdeal.* to 'testUSER'@'localhost';
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [mysql]> grant all previleges on fairdeal.* to 'testUSER'@'%';
    Query OK, 0 rows affected (0.00 sec)
    



2. DB 접근경로 세팅

  • phpMyAdmin 설치 (현재 포스팅)
  • 웹환경이 아닌 경우 접속자 로컬에서 Workbench 설치 (서버쪽 작업 X)
    [root@centos7 ~]# yum install epel-release /* epel repo 설치 안되어있다면 설치 */
    [root@centos7 ~]# yum install phpmyadmin
    
  • 접근허용 IP 추가
    [root@centos7 ~]# sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
    [root@centos7 ~]# sudo systemctl restart httpd
    
  • 웹에서 접근 시 “ip혹은 도메인”/phpMyAdmin