MySQLベース2:マスターコピー

5183 ワード

# mysql      :
1.    start slave       。
2.         ,    binlog           。
3.         ,        ,       ,                  。
4.             ,          relay log ,           master-info 。
5.  SQL       relay-log,    ,       SQL            ,   relay-log.info             。
mysql         :

#   :
1.  bin-log   (  mysql    show variables where variable_name like 'bin%'    ,      ON    ,OFF     bin-log       my.cnf     bin-log)
2.          replication slave  (grant replication slave on db_name.tb_name to 'user_name'@'host_name' identified by 'password';)
3.       (flush table with read lock;)
4.  master   ,  (replication slave username and password , master status filename and master status position(get master status: show master status ) )
5.      ,  (unlock tables;)

#   :
1.         
2.       (change master to master_host='host_name',master_port='master_port',master_user='master_user',paster_password='master_password',master_log_file='master_status_log_file',master_log_pos='master_status_log_position');
3.      ,start slave;         OK(show slave status\G;)       NO ,       master slave,        OK

 
#     
vim /etc/my.cnf
##############################################
[mysqld]
datadir = /data/mysql
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
user = mysql
port = 3306
server-id = 97
log-bin = mysql-bin
slow_query_log_file = /var/log/mysql/slow.log
slow_query_log = 1
symbolic-links = 0
log-error=/var/log/mysql/mysql_error.log
##############################################

#     
vim /etc/my.cnf
##############################################
[mysqld]
datadir = /data/mysql
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
user = mysql
port = 3306
server-id = 98
log-bin = mysql-bin
# slave      
read_only = 1
#       
relay_log = /var/log/mysql-relay-bin
slow_query_log_file = /var/log/mysql/slow.log
slow_query_log = 1
symbolic-links = 0
log-error=/var/log/mysql/mysql_error.log
##############################################

# master        
mysql > GRANT REPLICATION SLAVE ON *.* to 'root'@'%' identified by ' Password1!';
mysql > FLUSH PRIVILEGES;

#  slave   master
mysql > change master to master_host='172.50.1.97',master_user='root',master_password='Password1!',master_log_file='mysql-bin.000001',master_log_pos=687;

#  slave   slave  
mysql > start slave;

#  slave     
mysql > show slave status;