mysql master configuration from the primary master and

mysql1 are uploaded and mysql Source Package mysql-5.6.26.tar.gz, and then mysql1 source compiler are mounted mysql mysql:

cd

tar xf mysql-5.6.26.tar.gz -C /usr/local/src && cd /usr/local/src/mysql-5.6.26 && useradd -M -s /sbin/nologin mysql && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL-USER=mysql && make -j 8 && make install &&

cd && chown -R mysql:mysql /usr/local/mysql/

cp /etc/my.cnf /etc/my.cnf.bak

rm -fr /etc/my.cnf

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

chkconfig mysqld on

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

ln -s /usr/local/mysql/bin/* /bin/

/etc/init.d/mysqld start

mysql_secure_installation

A, mysql master-slave configuration:

1, the main mysql

192.168.146.13 :

Create a database to be synchronized:

mysql>create database HA;

mysql>use HA;

mysql> create table test(id int,name char(20));

mysql> insert into test values(‘001’,’zhangsan’);

/etc/init.d/mysqld stop

vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

Add the following four lines:

log-bin = mysql-bin-master # enable binary logging

server-id = 1 # native database ID Flag

binlog-do-db = HA # can be replicated from the server database. Binary need to synchronize the database name

binlog-ignore-db = mysql # may not be copied from the server library

Restart mysql:

/etc/init.d/mysqld restart

Authorization:

mysql>grant replication slave on . to [email protected] identified by "123456";

MySQL> Grant Slave Replication ON . to Slave @ '%' IDENTIFIED by "123456"; ip can be granted to any synchronization.

View status information:

mysql> show master status;

mysql-master-bin.000001

View binary log:

ls /usr/local/mysql/data/

mysql> show binlog events\G

Before copying To ensure consistent synchronization of databases, export database

mysqldump -uroot -p123456 HA> HA.sql # Export database

Pass from the exported database server

Method a: scp HA.sql [email protected]: / root

or

Remember to empty two servers iptables, or else port can not communicate

iptables –F

/etc/init.d/iptables stop

chkconfig iptables off

mysql2:

Two database servers mysql version to be consistent

mysql> show variables like '%version%';

2, from mysql

192.168.146.14 :

Modify the configuration file from the server:

From the server is not necessary to open the bin-log log

vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

Increase Row 1 below:

server-id = 2 # from the server ID number, and not the same as the main ID, if from a plurality of servers, each must have a unique server-id value from the server, the primary server, and must be further from the server is not the same . Server-id value may be considered similar to IP Address: The ID value uniquely identifying each server replicate real server cluster

/etc/init.d/mysqld restart

Test the connection to the primary server is successful

mysql -uslave -p123456 -h 192.168.146.13

Into the database, and consistent with the primary database server

msyql -uroot -p123456

mysql> create database HA;

mysql > use HA;

mysql > source HA < HA.sql

or:

mysql -uroot -p123456 HA < HA.sql

mysql> change master to master_host='192.168.146.13',master_user='slave',master_password='123456';

mysql> start slave;

mysql> show slave status \ G View Status

Yes is the emergence of two normal

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

The above step is done msyql master-slave configuration, if deployed as a main msyql - master configuration need continues as follows:

Two, mysql main master configuration:

1, mysql2 from

192.168.146.14:

vim /etc/my.cnf

Increase log-bin = mysql-bin-master # enable binary logging

  server-id= 2   

Increase binlog-do-db = HA # can be replicated from the server database. Binary need to synchronize the database name

Increase binlog-ignore-db = mysql # database can not be copied from the server

/etc/init.d/mysqld restart

Authorization:

mysql>grant replication slave on . to [email protected] identified by "123456";

Back mysql1:

mysql> change master to master_host='192. 168.146.14',master_user='slave',master_password='123456';

Third, re-synchronize all the data:

mysql> stop slave;

mysql> delete from test;

Back to the main mysql:

mysql> mysqldump -uroot -p123456 HA> HA.sql # Export database

scp HA.sql [email protected]:/root

Back from mysql:

mysql> mysql -uroot -p123456 HA < HA.sql

mysql> change master to master_host='192.168.146.13',master_user='slave',master_password='123456';

mysql> start slave;

mysql> show slave status \ G View Status

Fourth, resynchronize data of a node:

Main msyql:

mysql> show master status;

Record master_log_file = 'mysql-bin-master.000004' and master_log_pos = 360

From mysql:

mysql> stop slave;

mysql> delete from test;

mysql> change master to master_host='192.168.146.13',master_user='slave',master_password='123456',master_log_file='mysql-bin-master.000004',master_log_pos=360;

mysql> start slave;

Guess you like

Origin blog.51cto.com/hzcto/2405318