Deploying and Tuning 2.7 MySQL master-slave configuration-1

Source: Internet
Author: User
Tags mysql backup

MySQL master-slave (MySQL Replication), mainly used for MySQL backup or read-write separation. Before you configure the configuration, configure two MySQL servers, and if your machine cannot run two Linux VMS at the same time, consider running two MySQL services on the same machine.

MySQL Master-Slave principle is very simple, summed up:

Only one master can be set from each.
After the master executes the SQL, log the binary log file (Bin-log).
From the connection master, and get Binlog from the master, save in local relay-log, and execute SQL from the location you last remembered, and stop synchronizing once an error is encountered.

Judging from these Replication principles, these inferences can be inferred:

Master-slave database is not real-time synchronization, even if the network connection is normal, there is an instant, master-slave data inconsistency.

If the master-slave network is disconnected, from the network after normal, batch synchronization.

If you modify the data from, then it is very likely from the execution of the main Bin-log error and stop synchronization, this is a very dangerous operation. So in general, be very careful to modify the data from above.

A derivative configuration is a dual-master, mutual primary from the configuration, as long as the two sides of the modification does not conflict, can work well.

If you need a multi-master, you can use a ring configuration so that any node changes can be synchronized to all nodes.

Can be applied in a read/write separation scenario to reduce I/O for a single MySQL server

HA clusters that can implement MySQL services

Can be 1 master multiple from, can also be mutual master and slave (master)

////////////////////////////////////////////////////////////////////////////////////////////////

Install two MySQL on a single machine. Implement Master-Slave

Delete the original MySQL

rm-rf/usr/local/mysql/

Install MySQL

Switch to the download directory

cd/usr/local/src/

Extract

Tar zxvf mysql-5.1. -linux-x86_64-glibc23.tar.gz

Move

MV mysql-5.1. -linux-x86_64-glibc23/usr/local/mysql

Check that there are no MySQL users

' MySQL ' /etc/passwd

No words need to be created

Useradd-s/sbin/nologin MySQL

Copy the configuration file, overwriting the original

CP support-files/my-small.cnf  /ETC/MY.CNF
CP Support-files/mysql.server/etc/init.d/mysqld

Edit the configuration file, specify the installation path and data path for MySQL

Vim/etc/init.d/mysqld
basedir=DataDir= modified to Basedir=/usr/local/mysqldatadir=/data/mysql

Delete the original MySQL

rm-rf/data/mysql/

From New generation MySQL, there are two OK normal

./scripts/mysql_install_db--user=mysql--datadir=/data/mysql

See if there are two directories under/data/mysql MySQL and test

ls/data/mysql/

Start MySQL

/etc/init.d/mysqld start

Install a second MySQL

Switch to the installation directory, copy the file rename the second MySQL name

Cd/usr/local
Cp-r MySQL Mysql_slave

Switch to a second MySQL directory, copy the configuration file

CD mysql_slave/
Cp/etc/my.cnf.

Modifying a configuration file

Vim MY.CNF
Port            3306socket          =/tmp/Mysql.sock changed to            Port3307socket          =/tmp/mysql_slave.sockdatadir         =/data/mysql_slave

Generate Mysql_slave

./scripts/mysql_install_db--user=mysql--datadir=/data/mysql_slave

modifying startup scripts

cd/etc/init.d/
basedir=/usr/local/mysqldatadir=/data/mysql change to basedir=/usr/local/mysql_slavedatadir= /data/mysql_slave
conf= $dasedir/my.conf

Start

/etc/init.d/mysqldslave start

Deploying and Tuning 2.7 MySQL master-slave configuration-1

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.