생계/MySQL2017. 9. 8. 23:36


1. 복제 설정

1.1 GRANT REPLICATION SLAVE

 

@all

 

GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.*

TO replicant@'%'

IDENTIFIED BY 'replicant';

 

 

1.2 my.cnf 편집

 @Master

 

 cd /var/log

 mkdir /var/log/mysql

 

 chown R mysql.mysql ./mysql

 

 service mysqld stop

 

  vi /etc/my.cnf






 

log_bin = /var/log/mysql/mariadb-bin

 

[mysqld]

server_id = 101

relay_log = db01-relay-binlog







@Slave

 

service mysqld stop

 

vi /etc/my.cnf

 

[mysqld]

server_id = 102

read_only
 



@Master, Slave

service mysqld start



 

1.3 복제 설정

@Master

 

Ifconfig



 


mysql -u root -p

show master status;





@Slave

 

CHANGE MASTER TO MASTER_HOST='10.10.10.51',

MASTER_USER = 'replicant',

MASTER_PASSWORD = 'replicant',

MASTER_PORT=33060,

MASTER_LOG_FILE = 'mariadb-bin.000002',

MASTER_LOG_POS = 330;

 

START SLAVE; 




 

2. 복제 동작 확인

2.1show slave status 로 확인

 

@Slave

 

 

SHOW SLAVE STATUS;

Slave_IO_Running | Slave_SQL_Running  => yes 인가?






2.2 global_status 에서 확인

 

use mysql

 

SELECT variable_value

FROM information_schema.global_status

WHERE variable_name='SLAVE_RUNNING';






 

3. 복제 테스트

3.1 기본 설정

 

@Master

 

CREATE DATABASE IF NOT EXISTS temp;

USE temp;

 

CREATE TABLE doctors(

id int NOT NULL AUTO_INCREMENT PRIMARY KEY,

given_names varchar(255),

surname varchar(255),

birthdate date);

 

INSERT INTO doctors VALUES(1,'William','Hartnell','1908-01-08');

INSERT INTO doctors VALUES(2,'Patrick','Troughton','1920-03-25');

INSERT INTO doctors VALUES(3,'John','Pertwee','1919-07-07');

INSERT INTO doctors VALUES(4,'Tom','Baker','1934-01-20');

 

 

@Slave

 

show databases;

use temp

show tables;

select * from doctors;

 

3.2 Replicate_ignore_db

 

 

-     stop slave, 확인

 

MariaDB [(none)]> stop slave;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> SELECT variable_value

               -> FROM information_schema.global_status

               -> WHERE variable_name='SLAVE_RUNNING';

+----------------+

| variable_value |

+----------------+

| OFF            |

+----------------+

1 row in set (0.00 sec)

 

MariaDB [(none)]> exit

Bye

 

-     my.cnf replicate_ignore_db 추가

 

[mysql@localhost ~]$ vi /etc/my.cnf

 

...

[mysqld]

replicate_ignore_db='information_schema'

replicate_ignore_db='performance_schema'

replicate_ignore_db='mysql'

...

 

 

-    mysqld 재기동, slave 재시작

 

[mysql@localhost ~]$ service mysqld restart

 

 

[mysql@localhost ~]$ sql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 13

Server version: 10.2.7-MariaDB-log MariaDB Server

 

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> start slave;

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

MariaDB [(none)]> stop slave;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> start slave;

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> show slave status;

 

 

-     복제 테스트 ( ignore 확인)

 

@Master

 

MariaDB [temp]> use mysql

Database changed

MariaDB [mysql]> show tables;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| column_stats              |

| columns_priv              |

| db                        |

| event                     |

| func                      |

| general_log               |

| gtid_slave_pos            |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| host                      |

| index_stats               |

| innodb_index_stats        |

| innodb_table_stats        |

| plugin                    |

| proc                      |

| procs_priv                |

| proxies_priv              |

| reptest                   |

| roles_mapping             |

| servers                   |

| slow_log                  |

| table_stats               |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

31 rows in set (0.00 sec)

 

MariaDB [mysql]> create table aaaa(a int);

Query OK, 0 rows affected (0.02 sec)

 

 

 

MariaDB [(none)]> use mysql

Database changed

MariaDB [mysql]> show tables;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| column_stats              |

| columns_priv              |

| db                        |

| event                     |

| func                      |

| general_log               |

| gtid_slave_pos            |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| host                      |

| index_stats               |

| innodb_index_stats        |

| innodb_table_stats        |

| plugin                    |

| proc                      |

| procs_priv                |

| proxies_priv              |

| reptest                   |

| roles_mapping             |

| servers                   |

| slow_log                  |

| table_stats               |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

31 rows in set (0.00 sec)

 

 

-    복제 테스트 ( 나머지는 되는가 확인)

 

MariaDB [mysql]> use temp

Database changed

MariaDB [temp]> show tables;

+----------------+

| Tables_in_temp |

+----------------+

| a              |

| doctors        |

+----------------+

2 rows in set (0.00 sec)

 

MariaDB [temp]> create table aaa(a int);

Query OK, 0 rows affected (0.02 sec)

 

 

 

MariaDB [mysql]> use temp;

Database changed

MariaDB [temp]> show tables;

+----------------+

| Tables_in_temp |

+----------------+

| a              |

| aaa            |

| doctors        |

+----------------+

3 rows in set (0.00 sec)

 

반응형
Posted by 돌고래트레이너
생계/MySQL2017. 9. 8. 23:35

- 1. mysql client 접속 


mysql -u root -p

use mysql
select host, user, password from user;

 

 - 2.1 create user 구문으로 유저생성

 

create user 'test'@'%' identified by 'test';

CREATE USER 'test'@'10.10.10.10' IDENTIFIED WITH 'mysql_native_password' AS
  #authentication_string# REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK;
=> IP추가 시 비밀번호 직접 넣지 않고 동일하게 생성

 - 2.2 insert 구문으로 유저생성

 

insert into user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject, authentication_string)
values ('localhost','test', password('test'),'','','','');

 

insert into user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject, authentication_string)
values ('%','test', password('test'),'','','','');

 

flush privileges;     -- * insert 구문으로 유저생성시엔 반드시 flush 해줘야 적용됨.

 

 - 3. 권한 grant

 

grant all privileges on temp.* to test@'localhost';
grant all privileges on temp.* to test@'%';

grant all privileges on *.* to test@'%';

 

  - 4. 권한 확인

 

show grants for test@'%';

 

 

반응형
Posted by 돌고래트레이너
생계/MySQL2017. 9. 8. 23:33

mariadb 설치하는 방법은 여러가지가 있고, 장단점이 있다. 


- source 설치 : 소스를 다운받아 컴파일하는 방식. 홈페이지에서 소스를 다운받았는데 컴파일오류가 나면 당황스럽다. 
- binary 설치 : 이미 컴파일된 바이너리를 다운받아 설치. 설정도 바꿀수 있고, 컴파일 에러도 피해갈수 있다. 
- yum 설치 : 가장쉽고 실패할 일이 거의 없다. 단점은 설정을 맘대로 바꾸기 힘들다는것 (ex, 설치계정, datadir..)


 binary 설치가 나의 경우엔 가장 적합했다. 




1.설치 준비


- 라이브러리

yum -y install gcc gcc-c++ libtermcap-devel gdbm-devel zlib* libxml* freetype* libpng* libjpeg* iconv flex gmp ncurses-devel cmake.x86_64 libaio

cd /usr/local/
wget -N https://downloads.mariadb.org/interstitial/mariadb-10.2.7/bintar-linux-x86_64/mariadb-10.2.7-linux-x86_64.tar.gz
tar zxvf mariadb-10.2.7-linux-x86_64.tar.gz

ln -s /usr/local/mariadb-10.2.7-linux-x86_64 /usr/local/mysql


# mariadb 사용자 및 그룹 추가
groupadd mysql
useradd -g mysql mysql
passwd mysql


# 권한설정
chown mysql.mysql -R mariadb-10.2.7-linux-x86_64
chmod 750 -R /usr/local/mariadb-10.2.7-linux-x86_64
chown mysql.mysql -R ./mariadb
chown mysql.mysql -R ./mariadb-10.2.7-linux-x86_64



2. 설치 및 설정값 편집 


# my.cnf 복사,편집  (아래 내용은 인터넷에서 가져온거라 잘은 모르겠음)
cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf

- 시스템 메모리가 4G이상일 때 : my-innodb-heavy-4G.cnf
- 시스템 메모리가 1G~2G일 때 : my-huge.cnf
- 시스템 메모리가 512MB정도 일 때 : my-large.cnf
- 시스템 메모리가 32MB~64MB정도 일 때 : my-medium.cnf
- 시스템 메모리가 64MB이하일 때 : my-small.cnf


vi /etc/my.cnf  ( default port 를 변경하고자 한다면.. default = 3306 ) 
[client]
port = 33060
[mysqld]
port = 33060



# mysql(mariadb) 실행데몬 복사

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chown mysql.mysql /etc/init.d/mysqld
chown mysql.mysql /etc/my.cnf

chmod 750 /etc/init.d/mysqld


# mysql 실행데몬 수정
vi /etc/init.d/mysqld


# DB디렉토리 지정 하고 저장 


basedir=/usr/local/mysql
datadir=/DATA01/mysql

chown mysql.mysql -R /DATA01



3. DB 작업 


# DB생성 (mysql 계정으로 로그인)

su - mysql
/usr/local/mariadb/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/DATA01/mysql


# mysql 구동 (mysql 계정으로 로그인)
service mysqld start


# PATH 설정 (mysql 계정으로 로그인)


cd
vi .bash_profile

맨 마지막 줄에
PATH=$PATH:/usr/local/mysql/bin


닫고 저장


source .bash_profile


mysqladmin -u root password 'root123!'


netstat -an |grep 3306


# drop database test

 


** mariadb basedir 경로 변경 -> mysql

반응형
Posted by 돌고래트레이너