MySQL構成マスター

1925 ワード

の準備を
  • インストールMySQL
  • メインMySQL
  • MySQL構成の変更
    # vim /etc/my.cnf
    [mysqld]
    server-id=1
    log-bin=/data/mysql/bin-log/bin-log
    
  • 同期アカウントの作成
    > GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by '123456';
    
  • 再起動MySQL
    # /etc/init.d/mysqld restart
    
  • クエリーmaster状態
    > show master status;
     +----------------+----------+--------------+------------------+-------------------+
     | File           | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
     +----------------+----------+--------------+------------------+-------------------+
     | bin-log.000004 |      308 |              |                  |                   |
     +----------------+----------+--------------+------------------+-------------------+
     1 row in set (0.00 sec)
     
    
    bin-logファイル名bin-log.000004とbin-log点308このときメインMySQLを操作しないで、状態値の変化を防止
  • MySQLから
  • 必要なディレクトリの作成
    # mkdir /data/mysql/log-relay
    
  • MySQL構成の変更
    # vi /etc/my.cnf
    [mysqld]
    server-id=2
    read_only=1
    relay_log=/data/mysql/log-relay/log-relay
    
  • 再起動MySQL
    # /etc/init.d/mysqld restart
    
  • 接続主MySQL
    > change master to master_host='10.10.10.81',master_user='mysync',master_password='123456',master_log_file='mysql-bin.000004',master_log_pos=308;
    
    master_host主MySQLのIPmaster_user主MySQLの同期アカウントmaster_password主MySQLの同期アカウントパスワードmaster_log_file主MySQLのbin-logファイル名master_log_pos主MySQLのbin-logポイント
  • レプリケーション機能の起動
    > start slave;
    
  • レプリケーション機能状態の確認
    > show slave status \G
    
    Slave_IO_RunningおよびSlave_SQL_RunningはいずれもYES正常運転を示す