linux学习笔记-第二十八课-MySQL主从复制,读写分离配置
MySQL主从配置
配置准备将要配置的数据库进行主从同步,主从的服务器上都要有同一个数据库
一、配置mysql主服务器
[root@master ~]# vim /etc/my.cnf .................................... log-bin=mysql-bin <== 打开日志格式 .................................... server-id=1 <== 主从标记 ............................... 可选添加配置,筛选库 binlog-do-db=db1,db2 #需要同步的库 binlog-ignore-db=db1,db2 #忽略不同步的库 ............................. [root@master backup]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.42-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> grant replication slave on *.* to ‘repl‘@‘192.168.1.13‘ identified by ‘123‘; Query OK, 0 rows affected (0.00 sec) mysql>mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec) mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000014 | 332 | | | +------------------+----------+--------------+------------------+
二、配置mysql从服务器
# 修改从mysql的配置文件 [root@slave ~]# vim /etc/my.cnf ............................... server-id=2 修改id号,用来区分主从服务器标识 ............................... [root@slave tmp]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.5.43-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> slave stop; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> change master to master_host=‘192.168.1.11‘, master_port=3306, master_user=‘repl‘, master_password=‘123‘, master_log_file=‘mysql-bin.000014‘, master_log_pos=332; Query OK, 0 rows affected (0.08 sec) mysql> slave start; Query OK, 0 rows affected (0.01 sec) mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.11 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000014 Read_Master_Log_Pos: 332 Relay_Log_File: slave-relay-bin.000003 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000014 # 这部分提示为,YES 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: 332 Relay_Log_Space: 409 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 # 这部分没有错误提示,OK Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec) ERROR: No query specified
接下来就可以测试主从服务器了
本文出自 “Topspeed_King” 博客,请务必保留此出处http://mylinuxlife.blog.51cto.com/4706737/1656898
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。