MySQL Replication - Master and Slave


We have 2 servers that will be configured as Master and Slave.
After we install mysql-server on both servers, check /etc/hosts should be same as both servers.
# more /etc/hosts
127.0.0.1 localhost
192.168.0.21 servera
192.168.0.22 serverb
192.168.0.23 dbhost

After that try to look at /etc/my.cnf
At Master :
# more /etc/my.cnf
[MYSQLD]
basedir = /usr/local/mysql
datadir = /data/mysql/data
max_connections=10000
default-character-set=utf8
default-collation=utf8_bin

# InnoDB parameters
set-variable = innodb_buffer_pool_size=1500M
set-variable = innodb_additional_mem_pool_size=500M
set-variable = innodb_log_buffer_size=10M

log-bin=servera-bin
binlog-do-db=dsc_fleet
binlog-do-db=dsc_friend
binlog-do-db=dsc_info
binlog-do-db=dsc_marketing
binlog-ignore-db=mysql

server-id=1
#information for becoming slave.
master-host = serverb
master-user = replica
master-password = slave123
master-port = 3306
relay-log=servera-relay-bin
# remember to add line above

[mysql.server]
user=mysql
basedir=/usr/local/mysql

[mysqld_safe]
err-log=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid

[mysql]
default-character-set=utf8

At Slave :
# more /etc/my.cnf
[MYSQLD]
basedir = /usr/local/mysql
datadir = /data/mysql/data
max_connections=10000
default-character-set=utf8
default-collation=utf8_bin

# InnoDB parameters
set-variable = innodb_buffer_pool_size=1500M
set-variable = innodb_additional_mem_pool_size=500M
set-variable = innodb_log_buffer_size=10M

log-bin=serverb-bin
binlog-do-db=dsc_fleet
binlog-do-db=dsc_friend
binlog-do-db=dsc_info
binlog-do-db=dsc_marketing
binlog-ignore-db=mysql

server-id=2
#information for becoming slave.
master-host = servera
master-user = replica
master-password = slave123
master-port = 3306
relay-log=serverb-relay-bin
# remember to add line above

[mysql.server]
user=mysql
basedir=/usr/local/mysql

[mysqld_safe]
err-log=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid

[mysql]
default-character-set=utf8

If you want to add a database ( ex: dbex )that will be replicate, add this line at MYSQLD section.
-------------
binlog-do-db=dbex
-------------

start your sql server on both servers:
# /etc/init.d/mysql.server start

login to sql and add grant to user "replica" on both servers.
# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.33-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'replica'@'%' IDENTIFIED BY 'slave123';

restart your sql server on both servers:
# /etc/init.d/mysql.server restart

if you still found problem that Slave can't be started with "start slave" at mysql prompt for slave server, like this :

mysql> start slave;
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log

try to reset slave
mysql> reset slave;

Succesfull replication can be check with :
on Master server :
mysql> SHOW MASTER STATUS \G;
*************************** 1. row ***************************
File: servera-bin.000013
Position: 98
Binlog_Do_DB: dsc_fleet,dsc_friend,dsc_info,dsc_marketing
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)

ERROR:
No query specified

on Slave server :
mysql> SHOW SLAVE STATUS \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: servera
Master_User: replica
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: servera-bin.000013
Read_Master_Log_Pos: 98
Relay_Log_File: serverb-relay-bin.000039
Relay_Log_Pos: 237
Relay_Master_Log_File: servera-bin.000013
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 98
Relay_Log_Space: 237
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
1 row in set (0.00 sec)

ERROR:
No query specified

Thanks to Mas Yudy for help me at this issue.

Popular posts from this blog

Howto configure boot device order on ILOM

SAN Switch Config Command

Howto cstm on HP-UX