MySQL database Master/Slave server in Linux

Source: Internet
Author: User

MySQL database Master/Slave server in Linux

1. Network Configuration
Server:
[Root @ CentOS mysql-5.0.40] # ifconfig eth0
Eth0 Link encap: Ethernet HWaddr 08: 00: 27: 56: AA
Inet addr: 2.2.2.135 Bcast: 2.20.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 FIG: 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

Server B:
[Root @ centos1 ~] # Ifconfig eth0
Eth0 Link encap: Ethernet HWaddr 08: 00: 27: 56: 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 FIG: 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 bytes ed, 0% packet loss, time 1003 ms
Rtt min/avg/max/mdev = 0.758/0.760/0.763/0.027 MS
[Root @ centos1 ~] #

2. Install mysql software
Server:
[Root @ centos mysql-5.0.40] # yum install mysql-server-y -- install mysql
[Root @ centos mysql-5.0.40] #/etc/init. d/mysqld restart -- start 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,201 2, 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; -- create the database to be shared
Query OK, 1 row affected (0.01 sec)
Mysql> grant all privileges on *. * to abc @ '*' identified by 'system'; -- authorize the database
Query OK, 0 rows affected (0.01 sec)
Mysql>
[Root @ centos mysql-5.0.40] # vim/etc/my. cnf -- Add the following under 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 -- started successfully
Stopping mysqld: [OK]
Starting mysqld: [OK]
[Root @ centos mysql-5.0.40] #

Server B:
[Root @ centos1 ~] # Yum install 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,201 2, 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 ~] #

Recommended reading:

Load Nginx in Ubuntu for high-performance WEB Server 5 --- MySQL master/Master Synchronization

Production Environment MySQL master/Master synchronization primary key conflict handling

MySQL Master/Slave failure error Got fatal error 1236

MySQL master-slave replication, implemented on a single server

  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.