ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • MariaDB install and change datadir
    Tech/DS 2017. 5. 21. 09:53
    반응형

    yum repository 를 추가한다.

    # vi /etc/yum.repos.d/MariaDB.repo
    [mariadb]
    name = MariaDB
    gpgcheck=1

    #yum repolist
    #yum -y install mariadb-server mariadb-client

    아래와 같은 문구가 나오면 메모하도록 한다
    해당 내용은 root 패스워드 설정할때 사용한다.

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
    To do so, start the server, then issue the following commands:

    '/usr/bin/mysqladmin' -u root password 'new-password'
    '/usr/bin/mysqladmin' -u root -h vm1495003023679.localdomain password 'new-password'

    Alternatively you can run:
    '/usr/bin/mysql_secure_installation'
    which will also give you the option of removing the test
    databases and anonymous user created by default.  This is
    strongly recommended for production servers.


    mariadb 시작
    #systemctl start mariadb
    자동 재시작
    #systemctl enable mariadb

    mariadb root 패스워드 설정
    #/usr/bin/mysqladmin -u root password 'xxxxxxx'

    접속
    #mysql -u root -p
    Enter password: xxxxxx

    보안을 고려하여 비어있거나 사용하지 않는 디비는 삭제한다.
    >use mysql

    모든 외부 아이피 접속 허용 > INSERT INTO mysql.user (host,user,password) VALUES ('%','root',password('password')); > GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

    >  grant all privileges on *.* to root@localhost identified by 'xxxxxx';
    > delete from user where user='';
    >  delete from db where user='';
    > drop database test;

    외부접속 허용 설정

    MariaDB [mysql]> select host,user , password from mysql.user;
    MariaDB [mysql]> insert into mysql.user (host,user,password) values ('%','root',password('xxxxxxx'));
    MariaDB [mysql]> grant all privileges on *.* to 'root'@'%';
    MariaDB [mysql]> flush privileges;
    MariaDB [mysql]> exit

    재시작
    # systemctl restart mariadb


    datadir 변경 설정 
    /var/lin/mysql 을 /mnt/data/ 로 변경 한다.

    현재 디렉터리 확인
    # mysql -u root -p -e "select @@datadir"

    mariadb 중지
    #systemctl stop mariadb
    # systemctl is-active mariadb

    기존 데이터 동기화
    # rsync -av /var/lib/mysql/ /mnt/data/mysql

    rsync 를 사용하여 동기화 하면 해당 디렉터리의 권한까지 동기화 됨.

    기존 데이터 백업
    # mv /var/lib/mysql/ /var/lib/mysql.bak

    설정 파일 복사 및 오버라이팅 
    /usr/share/mysql 폴더에는 기본적인 설정 파일들이 사양별로 존재함
    my-small.cnf, my-medium.cnf, my-huge.cnf,,,,,

    서버 메모리 사양에 따라 cnf 파일을 사용한다.

    my-small.cnf 

    64MB 이하 메모리 

     my-medium.cnf

    128MB 

     my-large.cnf

    512MB 

     my-huge.cnf

    1~2G 

     my-innodb-heavy-4G.cnf

    4G , innoDB Storage 엔진만을 사용하는 환경 

     





    # cp /usr/share/mysql/my-small.cnf  /etc/my.cnf

    /etc/my.cnf 를 아래와 같이 수정 한다.
    #vi /etc/my.cnf

    [client]
    port        = 3306
    socket        = /mnt/data/mysql/mysql.sock
    default-character-set    = utf8

    [mysqld]
    character-set-server    = utf8
    collation-server    = utf8_general_ci
    datadir        = /mnt/data/mysql
    port        = 3306
    socket        = /mnt/data/mysql/mysql.sock

    [mysqldump]
    default-character-set    = utf8

    [mysql]
    default-character-set    = utf8

    재시작
    #systemctl start mariadb

    변경 디렉터리 확인

    #mysql -u root -p

    MariaDB > select @@datadir; 


    반응형

    'Tech > DS' 카테고리의 다른 글

    Postgresql session issue 해결방법  (0) 2017.06.02
    MariaDB Partioning  (0) 2017.06.02
    Mariadb log 활성화  (0) 2017.05.31
    DB size query  (0) 2017.05.30
    MariaDB clustering  (0) 2017.05.22
Designed by Tistory.