MySQL-5.6+MySQL-Proxy构建主从复制与读写分离(四)

2014-11-24 17:24:55 · 作者: · 浏览: 5
e when starting the server.



4)复制配置文件并设置启动脚本


[root@node1 mysql]# cp my.cnf /etc/my.cnf


cp:是否覆盖"/etc/my.cnf"? y


[root@node1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld[root@master mysql]# chmod +x /etc/init.d/mysqld


[root@master mysql]# chkconfig --add mysqld


[root@master mysql]# chkconfig mysqld on



5)开启二进制日志


[root@master mysql]# mkdir /usr/local/mysql/logs


[root@master mysql]# chown -R mysql:mysql /usr/local/mysql/logs/


[root@master mysql]# vi /etc/my.cnf


[mysqld]


#开启二进制日志


log-bin = /usr/local/mysql/logs/sql-bin


#唯一编号 [一般取IP的后两位]


server_id = 10



6)设置MySQL环境变量


[root@master mysql]# vi /etc/profile.d/mysql.sh


PATH=$PATH:/usr/local/mysql/bin:


[root@master mysql]# source /etc/profile



7)启动MySQL


[root@master mysql]# service mysqld start


Starting MySQL............ SUCCESS!


[root@master mysql]# netstat -antup |grep 3306


tcp 0 0 :::3306 :::* LISTEN 1768/mysqld


#salve步骤一样,这里省略...



——主从复制


1)在master上的MySQL创建相关用户


[root@node1 mysql]# mysql -u root


Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 1


Server version: 5.6.16-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)


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.11' identified by '12345';


Query OK, 0 rows affected (1.49 sec)



2)查询二进制日志


mysql> show master status;


+----------------+----------+--------------+------------------+-------------------+


| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |


+----------------+----------+--------------+------------------+-------------------+


| sql-bin.000001 | 120 | | | |


+----------------+----------+--------------+------------------+-------------------+


1 row in set (0.12 sec)



3)配置slave服务器


[root@slave ~]# mysql -u root


Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 3


Server version: 5.5.25-log Source distribution


Copyright (c) 2000, 2011, 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> change master to[root@slave1 ~]# mysql -u root


Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 3


Server version: 5.5.25-log Source distribution


Copyright (c) 2000, 2011, 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> change master to


-> master_host='192.168.1.254',


-> master_user='repl',


-> master_password='12345',


-> master_log_file='sql-bin.000001',


-> master_log_pos=120;


Query OK, 0 rows affected (0.25 sec)



4)启动slave检测是否同步成功


mysql> start slave;


Query OK, 0 rows affected (0.00 sec)


mysql> show slave status\G;


*************************** 1. row ***************************


Slave_IO_State: Waiting for master to send event


Master_Host: 192.168.1.10


Master