ITeye博客

Mysql Replication set up

lam · 2014-03-17 23:58 · 数据库 · 数据库 · Markdown

MySQL Failover Circular Replication

Assume we have 2 servers: Server1 and Server2.

Server1 Settings

  1. Put the option file my.cnf to Server1 path /etc with these settings:

log-bin=mysql-bin server-id = 1 auto_increment_increment = 10 auto_increment_offset = 1

  1. Change mode/permission for my.cnf to rw_r__r_ else mysql will igonore it. sudo chmod 644 my.cnf

  2. Stop and start mysql. cd /Library/StartupItems/MySQLCOM sudo ./MySQLCOM stop sudo ./MySQLCOM start

  3. Configure the server:

create a user for replication process:

cd /usr/local/mysql/bin ./mysql -p -u root

create user replicant@'%' identified by 'password';

Grant access rights:

GRANT SELECT, PROCESS, FILE, SUPER, REPLICATION CLIENT, REPLICATION SLAVE, RELOAD ON . TO replicant@'%'; Flush Privileges;

Specify the info for the serve2:

CHANGE MASTER TO MASTER_HOST='ip_of_server2', MASTER_USER='replication_user_name_on_server2', MASTER_PASSWORD='replication_password_on_server2';

Start the listerner:

Start slave;

Verify whether the replication is working:

show slave status\G

Server2 Settings

  1. Put the option file my.cnf on to Server2 path /etc with these settings:

log-bin=mysql-bin server-id = 2 auto_increment_increment = 10 auto_increment_offset = 2

  1. Change mode/permission for my.cnf to rw_r__r_ else mysql will igonore it. sudo chmod 644 my.cnf

  2. Stop and start mysql. cd /Library/StartupItems/MySQLCOM sudo ./MySQLCOM stop sudo ./MySQLCOM start

  3. Configure the server:

create a user for replication process:

cd /usr/local/mysql/bin ./mysql -p -u root

create user replicant@'%' identified by 'password';

Grant access rights:

GRANT SELECT, PROCESS, FILE, SUPER, REPLICATION CLIENT, REPLICATION SLAVE, RELOAD ON . TO replicant@'%'; Flush Privileges;

Specify the info for the serve1:

CHANGE MASTER TO MASTER_HOST='ip_of_server1', MASTER_USER='replication_user_name_on_server1', MASTER_PASSWORD='replication_password_on_server1';

Example:

CHANGE MASTER TO MASTER_HOST='125.564.12.1',

MASTER_USER='replicant', MASTER_PASSWORD='password';

Load data from Server1:

Load Data from Master;

Start the listerner:

Start slave;

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。