为什么80%的码农都做不了架构师?>>>
1.准备两台装好mysql的机器
mysql单机安装步骤请参考https://my.oschina.net/qbj/blog/1850086
我的两台主机分别为 10.20.4.58 和10.20.4.59
58为mater机器 59为slave机器
在msater上的mysql创建一个用户
mysql> grant replication slave on *.* to 'repl'@'10.20.4.59' identified by '{yourPassword}';
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
{yourPassword} 自己设定的密码
2. 修改master(58)的my.cnf
server-id=58
log-bin=mysqlbin-log
binlog_format=mixedread-only=0
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
auto_increment_increment=2
auto_increment_offset=1
重启mysql服务
3. 修改slave(59)的my.cnf
server-id=59
log-bin=mysqlbin-log
binlog_format=mixedreplicate-ignore-db=information_schema
replicate-ignore-db=mysql
replicate-ignore-db=performance_schema
replicate-ignore-db=syslog-slave-updates=ON
重启mysql服务
4 . 查看master机器的状态,在mysql下运行
mysql> show master status\G
*************************** 1. row ***************************File: mysqlbin-log.000003Position: 1270Binlog_Do_DB: Binlog_Ignore_DB: information_schema,mysql,performance_schema,sys
Executed_Gtid_Set:
1 row in set (0.00 sec)
记住 Position和File
5. 在slave机器配置master的信息
mysql> CHANGE MASTER TO MASTER_HOST='10.20.4.58', MASTER_USER='repl', MASTER_PASSWORD='{yourPassword}', MASTER_LOG_FILE='mysqlbin-log.000003', MASTER_LOG_POS=1270;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
查看slave状态,如果 Slave_IO_Running和 Slave_SQL_Running都为Yes,说明配置就是成功了。
mysql> show slave status\G
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 10.20.4.58Master_User: replMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysqlbin-log.000004Read_Master_Log_Pos: 1270Relay_Log_File: microService59-relay-bin.000002Relay_Log_Pos: 323Relay_Master_Log_File: mysqlbin-log.000003Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: information_schema,mysql,performance_schema,sysReplicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 154Relay_Log_Space: 539Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 58Master_UUID: 24ab31cd-8738-11e8-8f03-000c290c1fa6Master_Info_File: /data/mysql/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version:
1 row in set (0.00 sec)
6. 验证
在master上创建一个表,看是否能够正常同步到slave机器上。