首页 数据库 mysql教程 在Linux系统中做MySQL数据库主从服务器

在Linux系统中做MySQL数据库主从服务器

Jun 07, 2016 pm 05:34 PM
mysql主从复制

在Linux系统中做MySQL数据库主从服务器 1.网络配置服务器A:[root@CentOS mysql-5.0.40]# ifconfig eth0 eth0 Link encap:E

在Linux系统中做MySQL数据库主从服务器

1.网络配置
服务器A:
[root@CentOS mysql-5.0.40]# ifconfig  eth0
eth0      Link encap:Ethernet  HWaddr 08:00:27:56:AA:AA
inet addr:2.2.2.135  Bcast:2.255.255.255  Mask:255.0.0.0
inet6 addr: fe80::a00:27ff:fe56:aaaa/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:104974 errors:0 dropped:0 overruns:0 frame:0
TX packets:54283 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:66204315 (63.1 MiB)  TX bytes:4929056 (4.7 MiB)
[root@centos mysql-5.0.40]# hostname
centos
[root@centos mysql-5.0.40]# vim /etc/hosts
2.2.2.145 centos1
2.2.2.135 centos

服务器B:
[root@centos1 ~]# ifconfig  eth0
eth0      Link encap:Ethernet  HWaddr 08:00:27:56:AA:AA
inet addr:2.2.2.145  Bcast:2.2.2.255  Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe56:aaaa/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:96078 errors:0 dropped:0 overruns:0 frame:0
TX packets:52141 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:60024368 (57.2 MiB)  TX bytes:34512758 (32.9 MiB)
[root@centos1 ~]# hostname
centos1
[root@centos1 ~]# vim /etc/hosts
2.2.2.135  centos
2.2.2.145  centos1
[root@centos1 ~]# ping -c 2 2.2.2.135
PING 2.2.2.135 (2.2.2.135) 56(84) bytes of data.
64 bytes from 2.2.2.135: icmp_seq=1 ttl=64 time=0.763 ms
64 bytes from 2.2.2.135: icmp_seq=2 ttl=64 time=0.758 ms
--- 2.2.2.135 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1003ms
rtt min/avg/max/mdev = 0.758/0.760/0.763/0.027 ms
[root@centos1 ~]#

2.安装mysql软件
服务器A:
[root@centos mysql-5.0.40]# yum install mysql mysql-server -y    --安装mysql
[root@centos mysql-5.0.40]# /etc/init.d/mysqld restart    --启动mysql
Stopping mysqld:                                          [  OK  ]
Starting mysqld:                                          [  OK  ]
[root@centos mysql-5.0.40]# netstat -an |grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                  LISTEN
[root@centos mysql-5.0.40]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, 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> create database tong;    --创建要共享的数据库
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on *.* to abc@'*' identified by 'system';  --给数据库授权
Query OK, 0 rows affected (0.01 sec)
mysql>
[root@centos mysql-5.0.40]# vim /etc/my.cnf  --在mysqld下添加以下
server_id=1
binlog-do-db=tong
binlog-ignore-db=mysql
bin-log=mysql-log
[root@centos mysql-5.0.40]# /etc/init.d/mysqld restart    --启动成功
Stopping mysqld:                                          [  OK  ]
Starting mysqld:                                          [  OK  ]
[root@centos mysql-5.0.40]#

服务器B:
[root@centos1 ~]# yum install mysql mysql-server
[root@centos1 ~]# /etc/init.d/mysqld  restart
Stopping mysqld:                                          [  OK  ]
Starting mysqld:                                          [  OK  ]
[root@centos1 ~]# netstat -an |grep 3306
tcp        0      0 127.0.0.1:3306              0.0.0.0:*                  LISTEN
[root@centos1 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, 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> create database tong;
Query OK, 1 row affected (0.00 sec)
mysql> quit
[root@centos1 ~]# vim /etc/my.cnf
server_id=2
master_host=2.2.2.135
master_user=abc
master_password=system
master-port=3306
replicate_do_db=tong
master_connect_retry=10
log-bin=mysql1-log
[root@centos1 ~]# /etc/init.d/mysqld  restart
Stopping mysqld:                                          [  OK  ]
Starting mysqld:                                          [  OK  ]
[root@centos1 ~]#

推荐阅读:

Ubuntu下Nginx做负载实现高性能WEB服务器5---MySQL主主同步

生产环境MySQL主主同步主键冲突处理

MySQL主从失败 错误Got fatal error 1236

MySQL主从复制,,单台服务器上实施

linux

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

数据备份与故障恢复:MySQL主从复制在集群模式下的重要性探讨 数据备份与故障恢复:MySQL主从复制在集群模式下的重要性探讨 Sep 08, 2023 am 09:03 AM

数据备份与故障恢复:MySQL主从复制在集群模式下的重要性探讨

解密MySQL主从复制:揭秘其集群模式下的关键实现机制 解密MySQL主从复制:揭秘其集群模式下的关键实现机制 Sep 10, 2023 am 09:28 AM

解密MySQL主从复制:揭秘其集群模式下的关键实现机制

从容应对高并发:MySQL主从复制作为集群技术的性能优势分析 从容应对高并发:MySQL主从复制作为集群技术的性能优势分析 Sep 10, 2023 pm 03:48 PM

从容应对高并发:MySQL主从复制作为集群技术的性能优势分析

优化数据库性能:MySQL主从复制在集群技术中的最佳使用方法 优化数据库性能:MySQL主从复制在集群技术中的最佳使用方法 Sep 10, 2023 am 08:24 AM

优化数据库性能:MySQL主从复制在集群技术中的最佳使用方法

MySQL主从复制属于集群技术还是负载均衡技术?解析和区别 MySQL主从复制属于集群技术还是负载均衡技术?解析和区别 Sep 10, 2023 am 08:40 AM

MySQL主从复制属于集群技术还是负载均衡技术?解析和区别

详解MySQL主从复制在集群技术中发挥的功能和优势 详解MySQL主从复制在集群技术中发挥的功能和优势 Sep 09, 2023 am 09:03 AM

详解MySQL主从复制在集群技术中发挥的功能和优势

理解MySQL主从复制的集群特性和非负载均衡应用场景 理解MySQL主从复制的集群特性和非负载均衡应用场景 Sep 11, 2023 am 11:04 AM

理解MySQL主从复制的集群特性和非负载均衡应用场景

挖掘MySQL主从复制的集群技术潜力:开源方案与商业解决方案比较评估 挖掘MySQL主从复制的集群技术潜力:开源方案与商业解决方案比较评估 Sep 08, 2023 pm 07:16 PM

挖掘MySQL主从复制的集群技术潜力:开源方案与商业解决方案比较评估

See all articles