search
HomeDatabaseMysql Tutorial在Linux系统中做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

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
数据备份与故障恢复:MySQL主从复制在集群模式下的重要性探讨数据备份与故障恢复:MySQL主从复制在集群模式下的重要性探讨Sep 08, 2023 am 09:03 AM

数据备份与故障恢复:MySQL主从复制在集群模式下的重要性探讨引言:近年来,随着数据规模和复杂性的不断增长,数据库的备份和故障恢复变得尤为重要。在分布式系统中,MySQL主从复制在集群模式下被广泛应用,以提供高可用性和容错性。本文将探讨MySQL主从复制在集群模式下的重要性,并给出一些代码示例。一、MySQL主从复制的基本原理及优势MySQL主从复制是一种通

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

从容应对高并发:MySQL主从复制作为集群技术的性能优势分析随着互联网的快速发展,用户对于网站和应用的访问量呈现出爆炸性增长的趋势。在这种高并发的情况下,如何保证系统的稳定性和性能成为了每个开发人员和系统管理员的重要任务。在数据库中,MySQL主从复制技术被广泛应用,成为了应对高并发的有效解决方案之一。本文将探讨MySQL主从复制作为集群技术的性能优势。首先

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

优化数据库性能:MySQL主从复制在集群技术中的最佳使用方法摘要:随着互联网的快速发展,数据库的性能问题成为了各个企业和组织关注的焦点。MySQL主从复制技术在解决数据库性能瓶颈方面发挥着重要作用。本文将介绍MySQL主从复制的概念及原理,以及在集群技术中的最佳使用方法,帮助读者优化数据库性能。一、引言随着数据量不断增加,数据库的性能问题日益突出。如何优化数

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

解密MySQL主从复制:揭秘其集群模式下的关键实现机制引言:在现代数据库系统中,数据的高可用性和灵活性是非常重要的。MySQL作为一款开源的关系型数据库管理系统,在满足用户需求方面具有广泛的应用性。而MySQL的主从复制是MySQL数据库架构中非常关键的一部分,用于实现数据的备份和高可用性。本文将重点揭秘MySQL主从复制的关键实现机制,特别是其在集群模式下

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

MySQL主从复制属于集群技术还是负载均衡技术?解析和区别摘要:MySQL主从复制是一种数据库复制技术,用于在多个服务器上同步数据库的数据。本文将从技术原理、应用场景和功能特点等方面来解析和区分MySQL主从复制与集群技术以及负载均衡技术的区别。引言:在现代互联网应用中,数据库的高可用性和扩展性是至关重要的。MySQL主从复制是一种常见的解决方案之一,但是,

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

详解MySQL主从复制在集群技术中发挥的功能和优势引言MySQL是一款功能强大的关系型数据库管理系统,广泛应用于各种大型网站和应用程序中。随着数据量的增大和访问请求的增加,单台MySQL服务器的压力也逐渐增大,为了提高数据库的性能和可靠性,人们开始采用集群技术,其中MySQL主从复制就是其中一种常用的技术手段。MySQL主从复制原理MySQL主从复制是指将一

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

随着互联网的快速发展,应用系统的数据量越来越大,对数据库的性能和可靠性要求也越来越高。MySQL作为最常用的开源关系型数据库之一,具有较高的性能和稳定性,被广泛应用在各种企业级应用中。而MySQL主从复制作为一种常用的数据复制方案,能够提高数据的可靠性和读写性能,被广泛应用在大规模数据应用中。MySQL主从复制的集群特性指的是通过复制机制将主数据库的数据同步

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

挖掘MySQL主从复制的集群技术潜力:开源方案与商业解决方案比较评估随着互联网业务的不断发展和数据量的不断增加,对于数据库集群方案的需求也日益强大。MySQL主从复制技术正好满足了这一需求,它能够将数据库的读写操作在多个节点上进行分别处理,提高了数据库的读取性能和可用性。本文将对MySQL主从复制的集群技术潜力进行挖掘,并对开源方案和商业解决方案进行比较评估

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.