MariaDB/MySQL - Timezone 알아보기

     

     

    이번 포스팅에서는 MariaDB, MySQL Timezone 변경 방법에 대해서 알아보도록 하겠습니다.

     

     

     

       MariaDB/MySQL - Timezone 이란?

     

     

     

     

    서버의 날짜와 시간 설정은 매우 중요한 설정입니다 만약 날짜와 시간이 다르게 지정되어 있을 경우 DB 데이터, 로그 데이터, 웹서버의 접속한 기록 등등 시간이 잘못 기록되기에 문제가 생길수 있습니다.

     

     

     

    서버 시스템에서 발생되는 부팅로그, FTP 로그, 커널로그는 서버 시스템의 지정되어 있는 날짜와 시간설정에 따라 로그가 기록되지만 DBMS(MariaDB, MySQL)은 서버의 시스템 시간이 아닌 DBMS에 지정되어 있는 시간의 설정으로 기록되어 별도의 설정이 필요합니다.

     

     

     

       MariaDB/MySQL - Timezone 임시적 적용

     

     

     

    아래의 내용과 같이 MariaDB/MySQL 에서 명령어로 적용시 MariaDB/MySQL 재시작시 초기화 되며, 다시 적용하여야 됩니다.

     

     

     

    1. MariaDB/MySQL - Timezone 확인

     

    MariaDB [(none)]> show global variables like '%time_zone%';
    +------------------+--------+
    | Variable_name    | Value  |
    +------------------+--------+
    | system_time_zone | UTC    |
    | time_zone        | SYSTEM |
    +------------------+--------+

     

     

     

    2. MariaDB/MySQL - Timezone 변경

     

    MariaDB [(none)]> SET GLOBAL time_zone='Asia/Seoul';
    MariaDB [(none)]> SET time_zone='Asia/Seoul';

     

     

     

    3. MariaDB/MySQL - Timezone 확인

     

    MariaDB [(none)]> show global variables like '%time_zone%';
    +------------------+------------+
    | Variable_name    | Value      |
    +------------------+------------+
    | system_time_zone | UTC        |
    | time_zone        | Asia/Seoul |
    +------------------+------------+

     

    위 내용을 확인하시면 timezone 이 Asia/Seoul로 변경된것을 확인하실 수 있습니다.

     

     

     

       MariaDB/MySQL - Timezone 영구적 적용

     

     

     

    아래의 내용과 같이 MariaDB/MySQL 에서 명령어로 적용시 MariaDB/MySQL 재시작시 초기화 되지 않으며, 다시 적용하지 않아도 됩니다.

     

     

     

    1. MariaDB/MySQL - my.cnf 파일 Timezone 추가

     

    vi /server/mariadb/etc/my.cnf
    
    [mysqld]
    default-time-zone='Asia/Seoul'

     

     

     

    2. MariaDB/MySQL - 재시작

     

    # systemctl restart mariadb

     

    Timezone 설정이 반영되기 위해 Mariadb 재시작하셔아 됩니다.

     

     

     

       MariaDB/MySQL - Timezone 표준 시간대 추가

     

     

     

    MariaDB/MySQL를 설치시 초기 표준 시간대 없으므로 설정되지 않으며 mysql_tzinfo_to_sql 로 시간대를 추가 하셔야 됩니다.

     

     

     

    1. MariaDB/MySQL - Timezone 변경 에러

     

    MariaDB [(none)]> SET GLOBAL time_zone='Asia/Seoul';
    ERROR 1298 (HY000): Unknown or incorrect time zone: 'Asia/Seoul'

     

    위 내용과 같이 Timezone 지정시 에러가 표시되면 표준 시간대를 추가하셔야 됩니다.

     

     

     

    2. MariaDB/MySQL - Timezone 추가

     

    사용법 : mysql_tzinfo_to_sql /[타임존 폴더]/[타임존] | mysql -uroot mysql

     

    # /server/mariadb/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | /server/mariadb/bin/mysql -uroot mysql
    Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
    Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
    Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.

     

    Warning 메세지는 Timezone 파일이 아니기 때문에 발생하는 메세지 이므로 무시하셔도 되며, 위 명령어를 실행하신 후 Timezone을 변경하시면 됩니다.

    Posted by 서버이야기