zoukankan      html  css  js  c++  java
  • 002. MySQL复制操作


    #### 1.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, a server restart is required.

    Binary logging _must_ be enabled on the master because the binary log is the basis for replicating changes from the master to its slaves. If binary logging is not enabled using the `log-bin` option, replication is not possible.

    To configure the binary log and server ID options, shut down the MySQL server and edit the `my.cnf` or `my.ini` file.
    >[mysqld]
    log-bin=mysql-bin
    server-id=1</pre>

    #### 2. 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, shut down the slave server and edit the `[mysqld]`section of the configuration file to specify a unique server ID. For example:
    >[mysqld]
    server-id=2

    #### 3 Creating a User for Replication


    Although you do not have to create an account specifically for replication, you should be aware that the replication user name and password are stored in plain text in the master info repository file or table.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.

    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';

    #### 4 Obtaining the Replication Master Binary Log Coordinates
    mysql> show master status;
    +------------------+----------+--------------+------------------+-------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | mysql-bin.000001 |      640 |              |                  |                   |
    +------------------+----------+--------------+------------------+-------------------+

    ####  5. 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='192.168.210.153',
        -> MASTER_USER='repl',
        -> MASTER_PASSWORD='slavepass',
        -> MASTER_LOG_FILE='mysql-bin.000001',
        -> MASTER_LOG_POS=640;
    ```

    mysql> **START SLAVE;**

    ### 6. Replication Formats
    Replication works because events written to the binary log are read from the master and then processed on the slave. The events are recorded within the binary log in different formats according to the type of event. The different replication formats used correspond to the binary logging format used when the events were recorded in the master's binary log. The correlation between binary logging formats and the terms used during replication are:

    *   When using statement-based binary logging, the master writes SQL statements to the binary log. Replication of the master to the slave works by executing the SQL statements on the slave. This is called statement-based replication (often abbreviated as SBR), which corresponds to the standard MySQL statement-based binary logging format. Replication capabilities in MySQL version 5.1.4 and earlier used this format exclusively.

    *   When using row-based logging, the master writes events to the binary log that indicate how individual table rows are changed. Replication of the master to the slave works by copying the events representing the changes to the table rows to the slave. This is called row-based replication (often abbreviated as RBR). In row-based replication, the master writes events to the binary log that indicate how individual table rows are changed.

    *   You can also configure MySQL to use a mix of both statement-based and row-based logging, depending on which is most appropriate for the change to be logged. This is calledmixed-format logging. When using mixed-format logging, a statement-based log is used by default. Depending on certain statements, and also the storage engine being used, the log is automatically switched to row-based in particular cases. Replication using the mixed format is often referred to as mixed-based replication or mixed-format replication. For more information, see

    In MySQL 5.6, **statement-based** format is the default.

    ### 7. Check Result
    mysql> show slave statusG
    ```
    SQL_Remaining_Delay: NULL
    Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
    Master_Retry_Count: 86400
     ```



  • 相关阅读:
    LitJson.JsonException: Can't assign value '2347089724' (type System.UInt32) to type System.Int64
    unity特效ParticleSystem在UI上缩放(自适应屏幕)
    unity特效ParticleSystem用到UI上
    数据结构-线性表
    数据结构-各种树的简单理解
    图解排序算法之堆排序
    图解排序算法之快速排序—三数取中法
    图解排序算法之归并排序
    排序算法
    CSS 选择器及优先级
  • 原文地址:https://www.cnblogs.com/roni/p/5749854.html
Copyright © 2011-2022 走看看