shell>apt-get install mysql-server |
mysql>grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
mysql>flush privieges; # 刷新授权信息
|
server_id=1 # 全局唯一的
log-bin=master-mysql-bin # 开启logbin功能并设置logbin文件的名称
binlog_ignore_db=mysql # 复制过滤,不同步mysql系统自带的数据库
binlog_cache_size=1M
binlog_format=mixed # 混合型复制模式,默认采用基于语句的复制,一旦发现基于语句的无法精确的复制时,就会采用基于行的复制。
|
shell>service mysql restart |
mysql>grant replication slave, replication client on *.* to 'root'@'*' identified by 'root';
mysql>flush privieges; # 刷新授权信息
|
mysql>show master status\G;
+-------------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------------+----------+--------------+------------------+-------------------+
| master-mysql-bin.000004 | 154 | | mysql | |
+-------------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
|
server_id=2 # 全局唯一的
log-bin=slave-mysql-bin # 开启了二进制日志,实际上不开也没关系,因为我们这个slave只是做slave,如果你这台slave还有可能要做别人的master的话那么必须开启
binlog_ignore_db=mysql
binlog_cache_size=1M
binlog_format=mixed
relay_log=mysql-relay-bin # 配置中继日志,用来存放从master的bin-log那边同步来的数据
log_slave_updates=1
read_only=1
|
shell>service mysql restart |
change master to master_host='192.168.49.130', # master 服务器的 IP
master_user='root', # 登录 master 服务器的用户
master_password='root', # 登录 master 服务器的密码
master_port=3306, # master 服务器的端口
master_log_file='master-mysql-bin.000001', # 通过show master status看到的 File
master_log_pos=154, # 通过show master status看到的position
master_connect_retry=30;
|
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.49.130
Master_User: root
Master_Port: 3306
Connect_Retry: 30
Master_Log_File: master-mysql-bin.000004
Read_Master_Log_Pos: 958
Relay_Log_File: mysql-relay-bin.000006
Relay_Log_Pos: 1131
Relay_Master_Log_File: master-mysql-bin.000004
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 958
Relay_Log_Space: 1338
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 598381b1-fc1b-11e7-b7b8-000c29625440
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
|
start slave; |
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.49.130
Master_User: root
Master_Port: 3306
Connect_Retry: 30
Master_Log_File: master-mysql-bin.000004
Read_Master_Log_Pos: 958
Relay_Log_File: mysql-relay-bin.000006
Relay_Log_Pos: 1131
Relay_Master_Log_File: master-mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 958
Relay_Log_Space: 1338
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 598381b1-fc1b-11e7-b7b8-000c29625440
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
|
stop slave; |
mysql> show processlist\G;
*************************** 1. row ***************************
Id: 9
User: root
Host: localhost
db: test
Command: Query
Time: 0
State: starting
Info: show processlist
*************************** 2. row ***************************
Id: 10
User: root
Host: 192.168.49.131:34626
db: NULL
Command: Binlog Dump
Time: 14
State: Master has sent all binlog to slave; waiting for more updates
Info: NULL
2 rows in set (0.00 sec)
|