现在的位置: 首页 > 综合 > 正文

mysql replication

2014年06月03日 ⁄ 综合 ⁄ 共 3868字 ⁄ 字号 评论关闭

The REPLICATION
CLIENT
 privilege enables the use of SHOW
MASTER STATUS
 and SHOW
SLAVE STATUS
.

The REPLICATION
SLAVE
 privilege should be granted to accounts that are used by slave servers to connect to the current server as their master. Without this privilege, the slave
cannot request updates that have been made to databases on the master server.

GRANTREPLICATION SLAVE,REPLICATION CLIENT,RELOAD,SUPER ON *.* TO'username@'domian' IDENTIFIED BY 'userpasswrod';

Setting the Replication Master Configuration

On a replication master, you must enable binary logging and establish a unique server ID. If this has not already been done, this part of master setup requires a server restart.

Binary logging must be
enabled on the master because the binary log is the basis for sending data changes from the master to its slaves. If binary logging is not enabled, replication will not be possible.

Each server within a replication group must be configured with a unique server ID. This ID is used to identify individual servers within the group, and must be a positive integer between 1 and (232)–1.
How you organize and select the numbers is entirely up to you.

To configure the binary log and server ID options, you will need to shut down your MySQL server and edit themy.cnf or my.ini file.
Add the following options to the configuration file within the [mysqld] section.
If these options already exist, but are commented out, uncomment the options and alter them according to your needs. For example, to enable binary logging using a log file name prefix of mysql-bin,
and configure a server ID of 1, use these lines:

[mysqld]
log-bin=mysql-bin
server-id=1

if your master is also a slave (DB1 is the master of DB2, DB2 is the master of DB3) in order for DB2 to log updates from his master DB1 to the binlog (so DB3 can read them)
you need to put "log-slave-updates" on my.cnf or my.ini

Setting the Replication Slave Configuration

On a replication slave, you must establish a unique server ID. If this has not already been done, this part of slave setup requires a server restart.

If the slave server ID is not already set, or the current value conflicts with the value that you have chosen for the master server, you should shut down your slave server and edit the configuration to specify a unique server ID. For example:

[mysqld]
server-id=2

After making the changes, restart the server.

In the mysql.log file it's say that we need to setup relay-log in case the server hostname change.
# Replication
relay-log=mysqld-relay-bin

So
I believe these Master Setup and Slave Setup should both have log-bin=xyz values that match in these docs, or leave them out and use the defaults.

Creating a User for Replication

Each slave must connect to the master using a MySQL user name and password, so there must be a user account on the master that the slave can use to connect. Any account can be used for this operation, providing it has been granted the REPLICATION
SLAVE
 privilege. You may wish to create a different account for each slave, or connect to the master using the same account for each slave.

You need not create an account specifically for replication. However, you should be aware that the user name and password will be stored in plain text within the master.info file
(see Section 16.2.2.2,
“Slave Status Logs”
). Therefore, you may want to create a separate account that has privileges only for the replication process, to minimize the possibility of compromise to other accounts.

To create a new acccount, use CREATE
USER
. To grant this account the privileges required for replication, use theGRANT statement.
If you create an account solely for the purposes of replication, that account needs only theREPLICATION
SLAVE
 privilege. For example, to set up a new user, repl,
that can connect for replication from any host within the mydomain.com domain,
issue these statements on the master:

mysql> CREATE USER 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.mydomain.com';

Setting the Master Configuration on the Slave

To set up the slave to communicate with the master for replication, you must tell the slave the necessary connection information. To do this, execute the following statement on the slave, replacing the option values with the actual values relevant to your system:

mysql> CHANGE MASTER TO
    ->     MASTER_HOST='master_host_name',
    ->     MASTER_USER='replication_user_name',
    ->     MASTER_PASSWORD='replication_password',
    ->     MASTER_LOG_FILE='recorded_log_file_name',
    ->     MASTER_LOG_POS=recorded_log_position;

抱歉!评论已关闭.