MySQL master-slave synchronization is a mature architecture with the following advantages: ① the query can be performed on the slave server (that is, the READ function we often call) to reduce the pressure on the master server; ② back up data from the master server to avoid affecting the services of the master server during the backup process; ③ when the master server encounters problems, you can switch to the slave server. So I often use this solution in project deployment and implementation. In view of the rigor of mysql in the production environment, I recommend using the MySQL source code compilation method of brother Zhang banquet.
Version 4 is updated as follows:
I. added the mysql5.1.38 compilation and installation process. The installation process still adopted the mysql Installation Method in the early stage of Zhang banquet, and abandoned the script control method;
2. The method for retrieving the master database from the database is still obtained using tar. The reason for not using mysqldump is that the actual configuration shows that this method has a high chance of failure, therefore, we have been using tar to take the complete snapshot of the primary database. Some netizens do not understand it too well. Here we will focus on it;
Iii. Although the configuration of mysql master-slave replication is relatively simple, it is also a handle blade. Because if the mistaken deletion of the image occurs on the master database, the slave database will also happen; therefore, standalone backup of the master table must be performed. FTP backup is also recommended;
4. binlog must be enabled, and the compliance with the production environment is strict. You are welcome to discuss this post and find out the bugs and errors to avoid misleading new users; I will keep an eye on and update this post (fuqin cooking)
Database directory and others
My. cnf configuration file/usr/local/webserver/mysql/my. cnf
Mysql database location/usr/local/webserver/mysql/data/
Primary Database: 192.168.4.191
Slave Database: 192.168.4.192
Operating System: RHEL5.4 64-bit
Server Type: HP 580G5, dual-core XeonE5520, 32 GB memory, 4 300GSAS into RAID 10
The compilation process of mysql5.1.38 source code is as follows:
- /Usr/sbin/groupadd mysql
- /Usr/sbin/useradd-g mysql
- Unzip mysql-5.1.38.zip
- Cd mysql-5.1.38/
- . /Configure -- prefix =/usr/local/webserver/mysql/-- enable-starter er -- with-extra-charsets = complex -- enable-thread-safe-client -- with-big-tables -- with-readline -- with-ssl -- with-embedded-server -- enable-local-infile -- with-plugins = innobase
- Make & make install
- Chmod + w/usr/local/webserver/mysql
- Chown-R mysql: mysql/usr/local/webserver/mysql
- Cp support-files/my-medium.cnf/usr/local/webserver/mysql/my. cnf
- # This depends on the specific environment. huge. cnf can be used for high-pressure conversion.
- Cd ../
① Create a data table as a mysql user account:
/Usr/local/webserver/mysql/bin/mysql_install_db -- basedir =/usr/local/webserver/mysql -- datadir =/usr/local/webserver/mysql/data -- user = mysql
② Start MySQL (last & indicates running in the background)
/Bin/sh/usr/local/webserver/mysql/bin/mysqld_safe -- defaults-file =/usr/local/webserver/mysql/my. cnf &