Mysql主从配置

来源:互联网 发布:翅片管换热器设计软件 编辑:程序博客网 时间:2024/06/16 18:28

首先,分别在两台服务器上装好mysql,我的安装路径是/usr/local/mysql,开始数据库里没有数据!!
两台服务器地址分别是主:10.0.0.1,从:10.0.0.2

主服务器配置

创建用户,用户从服务器连接

create user master;grant replicaiton slave on *.* to 'master'@'10.0.0.2' identified by 'master';

然后修改配置文件

[mysqld]server-id = 1log-bin = master-binlog-bin-index = master-bin.index

重启mysql, 此时可以查看主节点状态

mysql> show master status;+-------------------+----------+--------------+------------------+-------------------+| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+-------------------+----------+--------------+------------------+-------------------+| master-bin.000002 |      825 |              |                  |                   |+-------------------+----------+--------------+------------------+-------------------+1 row in set (0.00 sec)mysql> 

需要记住file和position的数据,下面要用

从节点配置

修改配置文件

[mysqld]server-id = 2relay-log-index = slave-relay-bin.indexrelay-log = slave-relay-bin

连接主节点,登录mysql

change master to master_host='10.0.0.1', //Master 服务器Ipmaster_port=3306,master_user='master',master_password='master',master_log_file='master-bin.000002',//Master服务器产生的日志master_log_pos=825;

重启Mysql,此时主从配置已经生效

0 0