MySQL Replication (Basic Principles and configurations of Master and Slave)
1. Working Principle of master-slave mysql server: (and Process Analysis)
Process:
Mysql replication is an asynchronous replication, from one Mysql instace (called Master) to another Mysql instance (called Slave ). The entire replication operation is completed by three processes, two of which are on Slave (SQL process and IO process), and the other on Master (IO process.
To implement replication, you must first enable the binary log (bin-log) function on the Master side. Otherwise, it cannot be implemented. The whole replication process is actually because Slave obtains the log from the Master end and then executes the operations recorded in the log in full order on itself.
The basic process of replication is as follows:
(1) the IO process on the Slave connects to the Master and requests the log content after the specified location of the specified log file (or the log from the beginning;
(2) After the Master receives a request from the Slave IO process, it reads the log information after the specified location of the log based on the request information by the IO process responsible for replication, the IO process returned to Slave. Besides the information contained in the log, the returned information also includes the name of the bin-log file on the Master end and the location of the bin-log;
(3) After the Slave IO process receives the information, it adds the received log content to the end of the relay-log file on the Slave end in sequence, and record the file name and location of the bin-log on the Master end to the master-info file, so that the next read can clearly show the High-Speed Master "I need to start from the location of a bin-log, please send it to me ";
(4) After the Slave SQL process detects the newly added content in relay-log, it will immediately parse the relay-log content into the executable content during actual execution on the Master end, and execute it on your own.
Now that you understand the principles, let's install mysql and configure the master-slave mysql server.
For ease of use, and to make mysql functions better we use binary package installation, (need to register, free): http://www.mysql.com/downloads/mysql/
2. Install mysql in binary mode (the process is not explained in detail ):
# Decompress the package and link
Tar xvf mysql-5.1.50-linux-i686-glibc23.tar.gz/usr/local
Cd/usr/local
Ln-sv mysql-5.1.50-linux-i686-glibc23.tar.gz mysql
Cd mysql
# Add a user and the permission (-r: Add a system user)
Groupadd mysql
Useradd-g mysql-s/sbin/nologin-M-r mysql
Mkdir/mysql/data
Chown-R mysql. mysql/data
Cd/usr/local/mysql
Chown mysql: mysql.-R
# Initializing mysql configurations
Scripts/mysql_install_db -- user = mysql -- datadir =/mysql/data
Chown root.-R
Chown mysql data/-R
Cp support-files/my-large.cnf/etc/my. cnf
Vim/etc/my. cnf
Datadir =/mysql/data # Add this line
# Start mysql
Bin/mysqld_safe -- user = mysql &
Netstat-nutlp | grep 3306
# Use the mysql Command
Vim/etc/profile
# Add
PATH = $ PATH:/usr/local/mysql/bin
./Etc/profile # repeat the configuration file
# Load database functions
Vim/etc/ld. so. conf. d/mysql. conf
# Add
/Usr/local/mysql/lib
Ldconfig-v
Ln-sv/usr/local/mysql/include/usr/include/mysql
Ls/usr/include/mysql/
# Add mysql to startup
Cp support-files/mysql. server/etc/init. d/mysqld
Chkconfig -- add mysqld
Chkconfig mysqld on
Service mysqld restart