mysqlプライマリ・セカンダリ・バックアップ


プライマリノード
my.cnf追加構成
log-bin=mysql-bin
log-bin-index=mysql-bin.index  
server-id       = 1
mysqlに接続し、次の文を実行します.
create user repl_user
GRANT REPLICATION SLAVE on *.* to repl_user IDENTIFIED by 'fuwenchao'
スレーブノード
server-id=2
relay-log=slave-relay-bin
relay-log-index=slave-ralay-bin.index
master-host=pacteralinux.chinacloudapp.cn
master-user=repl_user#同期ユーザーアカウント
master-password=fuwencaho_hot
プライマリノード
Aサーバーmysqlサービスを起動します.
入力show master status;#プライマリ・サーバのステータスの表示
mysql> show master status;
+---------------------+----------+--------------+------------------+
| File         |  Position  |  Binlog_Do_DB   | Binlog_Ignore_DB |+-----------------+----------+--------------+------------------+| mysql-bin.000008 |     106   | cdn      |    manual,mysql   |+-----------------+----------+--------------+------------------+
スレーブノード
mysqlサーバservice mysqld restartの再起動
失敗:エラーは次のとおりです.
[root@pacteralinux etc]# service mysqld restart
Shutting down MySQL..[  OK  ]
Starting MySQL....The server quit without updating PID file (/mnt/resource/mysqldate/pacteralinux.pid).[FAILED]
コメントを削除
master-host=pacteralinux.chinacloudapp.cn
master-user=repl_user#同期ユーザーアカウント
master-password=fuwencaho_hot
コードを参照:
[root@pacteralinux //]# more /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
socket =/mnt/resource/mysqldate/mysql.sock
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir =/usr/local/mysql
datadir =/mnt/resource/mysqldate
port =3306
socket =/mnt/resource/mysqldate/mysql.sock
default-storage-engine=MyISAM
server-id=2
relay-log=slave-relay-bin
relay-log-index=slave-ralay-bin.index
replicate-do-db=mysqldb
#master-host=A's hostname or IP
#master-user=repl_user    #�� �ㄦ� ���
#master-password=fuwenchao
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
lower_case_table_names= 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
innodb_use_sys_malloc =1

再起動成功
show slave statusは空に戻ります
ノードからプライマリノードを指定するには
mysql> change master to
   -> master_host='A'IP',
   -> master_port=3306,
   -> master_user='repl_user',
   -> master_password='fuwenchao';
Query OK, 0 rows affected, 2 warnings (3.51 sec)
mysql> start slave;
Query OK, 0 rows affected (0.25 sec)
これで、プライマリはバックアップから完了し、2つのデータベースは同期を維持し、数秒遅延します.
同期障害の解決
MySQL同期障害:「Slave_SQL_Running:No」の2つの解決策
1.まずSlaveサービスを停止します.slave stopはメインサーバにホストのステータスを表示します.FileとPositionの対応する値を記録します.3.slaveサーバで手動同期を実行するには:
mysql> show master status;+------------------+-----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+-----------+--------------+------------------+| mysql-bin.000020 | 135617781 | | |+------------------+-----------+--------------+------------------+1 row in set (0.00 sec)
mysql> change master to> master_host='master_ip',> master_user='user',> master_password='pwd',> master_port=3307,> master_log_file='mysql-bin.000020',> master_log_pos=135617781;1 row in set (0.00 sec)mysql> slave start;1 row in set (0.00 sec)
slaveステータスの検出を再度表示するには、次の手順に従います.
Slave_IO_Running: YesSlave_SQL_Running: Yes...Seconds_Behind_Master: 0
注意:この方法では、サーバからのデータが不完全になる可能性があります.例えば、サーバからエラーが発生した場合、プライマリ・サーバのログ・ファイルが増加し続け、長い時間が経過した後、プライマリ・サーバからログの位置を直接取得すると、エラー期間のデータがサーバから更新できない可能性があります.ここでは、次のような方法を提案する(エラー文を直接スキップ).
解決策II:
mysql> slave stop;mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;mysql> slave start;
set GLOBAL SQL_SLAVE_SKIP_COUNTER=Nは、バックアップの1つまたはNつのエラーのコピー文をスキップするために使用されます.そしてstart slaveを再起動すればいいです.