MySQL High availability (master standby)

Source: Internet
Author: User

Server basic Environment:

Two centos6.4, iptables diabled, SELinux disabled

The hosts analysis of the two units

MySQL installation (two identical operations):

MySQL Users and Groups

#groupadd MySQL

#useradd-R-G MySQL MySQL

MySQL's various usage directories

Data Catalog mount point:/data

Database Base directory:/usr/local/mysql

Database configuration file Location:/etc/my.cnf

Database Data Catalog:/data/mysql

InnoDB data and InnoDB log directory:/data/mysql

#mkdir/data/mysql

#mkdir/usr/local/mysql

MySQL Decompression

#tar zxvf/home/mysql-5.5.9.tar.gz-c/data

MySQL Compilation

#cmake. \

>-dcmake_install_prefix=/usr/local/mysql/\

>-dmysql_datadir=/data/mysql/\

>-dwith_innobase_storage_engine=1 \

>-denabled_local_infile=1 \

>-dmysql_tcp_port=3306 \

>-dextra_charsets=all \

>-ddefault_charset=utf8 \

>-DDEFAULT_COLLATION=UTF8-GENERAL_CI \

>-dwith_debug=

Enter

#make && make Install

MySQL configuration file

#cd/usr/local/mysql

#cp/data/mysql-5.5.9/support-files/my-medium.cnf/etc/my.cnf

MySQL startup script

#cp/data/mysql-5.5.9/support-files/mysql.server/etc/init.d/mysqld

#chmod +x/etc/init.d/mysqld

Initializing the database

#cd/usr/local/mysql

#./usr/local/mysql/scripts/mysql_install_db--user=mysql--ldata=/data/mysql

Start MySQL

#/etc/init.d/mysqld start

Set Root password

#mysql-uroot-p//At the time is the wood has the password direct return will be OK

Mysql>update Mysql.user set Password=password ("password") where user= "root";

MYSQ is the database name, user is the table name

Mysql>flush privileges;

Master-Slave configuration:

Primary server Configuration

Mysql>grant replication Slave on * * to ' mysql ' @ ' from server IP ' identified by ' password ';

Mysql>show Master status;

#vim/ETC/MY.CNF//need to change two places

Log-bin=mysql-bin//In general This is the display, Log-bin must be set to Mysql-bin, this entry to MySQL will produce many similar mysql-bin.00001 files, these files are mainly used to record data recovery, The operation of synchronizing data between master and slave servers. If you do not make the high availability, this option can be banned, so as not to affect system performance.

Server-id = 144//server-id is the thread used to identify the server, classes such as MySQL are highly available, the master thread and the slave thread use this to indicate. The ID of the master must be different (otherwise your I/O process will fail to communicate), even if it is a master n standby, then the ID of the n is the same.

From server settings

#vim/ETC/MY.CNF//need to change two places

Log-bin=mysql-bin

Server-id = 145

Mysql>change Master to master_host= ' master server IP ', master_user= ' MySQL ', master_password= ' password ';

Mysql>start slave

Mysql>show slave Status\g

I/O Processes and SQL threads must all communicate successfully!!!! Master ready to sync!!!

MySQL High availability (master standby)

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.