mysql> show master status; +------------------+----------+--------------+--------------------------------------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+--------------------------------------------------+-------------------+ | mysql-bin.000003 | 357 | db_java1234 | mysql,information_schema,performation_schema,sys | | +------------------+----------+--------------+--------------------------------------------------+-------------------+ 1 row in set (0.01 sec)
mysql> show slave status; Empty set
设置用户名
在master执行
1 2 3 4 5 6 7 8 9 10 11 12 13
# 创建用户名为slave1 # 172.20.0.3从库ip # 123456 密码 CREATE USER 'slave1'@'172.20.0.3' IDENTIFIED BY '123456';
# 语法:GRANT privileges ON databasename.tablename TO 'username'@'host' # 172.20.0.3 从库 # 两个权限:REPLICATION和SLAVE # *.* 所有的库和表 GRANT REPLICATION SLAVE ON *.* TO 'slave1'@'172.20.0.3';
# 刷新权限 FLUSH PRIVILEGES;
在slave执行
1 2 3 4
CHANGE MASTER TO MASTER_HOST='172.20.0.2',MASTER_USER='slave1',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=964;
# 开启主从 start slave;
在从库执行
1
show slave status;
主要看Slave_io_running =yes
主要看Slave_sql_running =yes
读写分离
scheml.xml
schema标签
1 2 3 4 5 6 7
<schema name="TESTDB" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="dn1"> <!-- auto sharding by id (long) --> <!--splitTableNames 启用<table name 属性使用逗号分割配置多个表,即多个表使用这个配置--> <table name="travelrecord,address" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" splitTableNames ="true"/> <!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate" /> --> </schema>