由於要寫一個訂閱MySQL binlog的基礎服務,因此須要配置一套MySQL主從,作開發環境,在這裏作個筆記。mysql
MySQL版本5.7.17sql
主庫配置架構
[mysqld] log_bin = /path/mysql/master/data/log_bin basedir = /usr/local/Cellar/mysql/5.7.17 datadir = /path/mysql/master/data port = 3306 server_id = 13306 socket = mysql.sock sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
從庫配置socket
[mysqld] log_bin = /path/mysql/slave/data/log_bin relay_log = /path/mysql/slave/data/relay_log relay-log-index = /path/mysql/slave/data/relay-log-index relay-log-info-file = /path/mysql/slave/data/relay-relay-log.info replicate-do-db = test log_slave_updates = 1 basedir = /usr/local/Cellar/mysql/5.7.17 datadir = /path/mysql/slave/data port = 3307 server_id = 13307 socket = mysql.sock sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
初始化主MySQL,user是root,密碼爲空,slave初始化改下datadir參數code
mysqld --initialize-insecure --user=root --datadir=/path/mysql/master/data
啓動主MySQL,啓動slave請改下defaults-file參數server
mysqld --defaults-file=/path/mysql/master/etc/my.cnf
在主庫建立一個同步帳戶開發
GRANT REPLICATION SLAVE ON *.* TO repl@'%' IDENTIFIED BY 'pwd'; FLUSH PRIVILEGES;
在從庫開啓同步同步
CHANGE MASTER TO MASTER_HOST='127.0.0.1',MASTER_PORT= 3306, MASTER_LOG_FILE='log_bin.000001', MASTER_LOG_POS=1, MASTER_BIND='', MASTER_USER='repl',MASTER_PASSWORD='pwd'; START SLAVE;
關閉主MySQL,關閉slave,請修改相應的地址和端口it
mysqladmin -uroot -p -h 127.0.0.1 -P 3306 shutdown
完成。ast
更多架構、PHP、GO相關踩坑實踐技巧請關注個人公衆號:PHP架構師