| 
                         ip地址不能写为%. 因为主从备份中,当前创建的用户,是给从库Slave访问主库Master使用的.用户必须有指定的访问地址.不能是通用地址. 
  
1.3.1.3.3 查看用户 
- use mysql;  
 - select host, name from user; 
 
  
1.3.1.3.4 查看Master信息 
- show master status; 
 
  
1.3.2 Slave[从库]配置
1.3.2.1 修改Slave配置文件
- /etc/my.cnf 
 
  
1.3.2.1.1 server_id 
唯一标识, 本环境中配置为 : 2 
1.3.2.1.2 log_bin 
可以使用默认配置, 也可以注释. 
1.3.2.2 可选: 修改uuid
主从模式要求多个MySQL物理名称不能相同. 即按装MySQL过程中Linux自动生成的物理标志. 唯一物理标志命名为uuid. 保存位置是MySQL数据库的数据存放位置. 默认为/var/lib/mysql目录中. 文件名是auto.cnf. 
修改auto.cnf文件中的uuid数据. 随意修改,不建议改变数据长度.建议改变数据内容. 
- /var/lib/mysql/auto.cnf 
 
  
1.3.2.3 重启MySQL服务
- service mysqld restart 
 
  
1.3.2.4 配置Slave
1.3.2.4.1 访问mysql 
- mysql -uusername -ppassword 
 
  
1.3.2.4.2 停止Slave功能 
- stop slave 
 
  
1.3.2.4.3 配置主库信息 
需要修改的数据是依据Master信息修改的.  ip是Master所在物理机IP. 用户名和密码是Master提供的Slave访问用户名和密码.  日志文件是在Master中查看的主库信息提供的.在Master中使用命令show master status查看日志文件名称. 
- change master to master_host=’ip’, master_user=’username’, master_password=’password’, master_log_file=’log_file_name’;  
 - change master to master_host='192.168.199.212', master_user='slave', master_password='slave', master_log_file='master_log.000001'; 
 
  
1.3.2.4.4 启动Slave功能 
- start slave; 
 
  
1.3.2.4.5 查看Slave配置 
- show slave status G;  
 - mysql> show slave status G;  
 - *************************** 1. row ***************************  
 - Slave_IO_State: Waiting for master to send event  
 - Master_Host: 192.168.120.139  
 - Master_User: slave  
 - Master_Port: 3306  
 - Connect_Retry: 60  
 - Master_Log_File: master-log.000001  
 - Read_Master_Log_Pos: 427  
 - Relay_Log_File: mysqld-relay-bin.000002  
 - Relay_Log_Pos: 591  
 - Relay_Master_Log_File: master-log.000001  
 - 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: 427  
 - Relay_Log_Space: 765  
 - 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 最后一次错误的IO请求编号  
 - Last_IO_Error:  
 - Last_SQL_Errno: 0 最后一次错误的执行SQL命令编号.  
 - Last_SQL_Error:  
 - Replicate_Ignore_Server_Ids:  
 - Master_Server_Id: 1  
 - Master_UUID: 9ee988ac-8751-11e7-8a95-000c2953ac06  
 - 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 the slave I/O thread to update it  
 - 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  
 - 1 row in set (0.00 sec) 
 
  
1.3.3 测试主从
1.4 主从模式下的逻辑图
  
2 MyCat读写分离配置                        (编辑:52站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |