mysqlマスターインストール構成
234790 ワード
1、mysql主従レプリケーションの紹介
1、概要主従レプリケーション、主にデータベースのデータセキュリティを実現し、IO性能と読み書き分離機能を向上させ、主データベースと一致するデータベース環境を構築する.データベースからマルチレベルのレプリケーションを実行できます.2、mysqlコピーのタイプ1.STATEMENTモード(SBR)は、データを変更するsql文ごとにbinlogに記録されます.利点は、各sql文と各行のデータ変化を記録する必要がなく、binlogログ量を削減し、IOを節約し、パフォーマンスを向上させることです.欠点は、場合によってはmaster-slaveのデータが一致しない(sleep()関数、last_insert_id()やuser-defined functions(udf)などで問題が発生します)
ROWモード(RBR)は、各sql文のコンテキスト情報を記録せず、どのデータが修正され、どのように修正されたかを記録するだけです.また、特定の場合のストレージ・プロシージャ、またはfunction、またはtriggerの呼び出しやトリガが正しくコピーされないという問題は発生しません.欠点は、大量のログが発生し、特にalter tableの場合、ログが急騰することです.
MIXEDモード(MBR)以上の2つのモードが混在して使用され、一般的なレプリケーションではSTATEMENTモードでbinlogが保存され、STATEMENTモードではコピーできない操作ではROWモードでbinlogが保存され、MySQLでは実行するSQL文に基づいてログ保存方式が選択されます.
3、同期原理1.Masterデータベースは変更が発生するとすぐにBinaryログファイルに記録する.SlaveデータベースはI/O thread接続Masterデータベースを起動し、Master変化のバイナリログ3を要求する.Slave I/Oで取得したバイナリログは、自分のRelayログファイルに保存されます.4.Slave SQL threadのタイミングでRealy logが変化しているかどうかをチェックし、変化したらデータを更新する
2、mysqlインストール
プライマリ・スレーブを構成する前に、プライマリ・スレーブのmysqlデータベースをインストールする必要があります.インストール方法は同じです.1、インストールパッケージをダウンロードしてサーバーにアップロードし、mysqlディレクトリに解凍する.
2、mysqlユーザーを作成し、授権する.
3、配置my.cnfファイル
4、インストールして、そしてランダムに生成したパスワードを覚えて、初めてログインして使う必要があります
5、ssl暗号化
7、サービスを開始する
8、自動生成されたパスワードDc(hW 5-o>JoNを使用してデータベースにログインし、rootパスワードを変更し、設定を変更してリモートログインを許可する.そうしないとERROR 1820(HY 000):You must reset your password using ALTER USER statement before executing this statement
3、主従同期の構成
1)マスターライブラリ構成my.cnf、次のパラメータを追加
2)マスターライブラリの構成
3)再起動、マスターライブラリ作成同期ユーザslave
4)スレーブmyを設定する.cnf
5)マスター・ライブラリ・データの同期ソース・ライブラリ・データのエクスポート
6)マスターライブラリからエクスポートされたデータファイルをターゲットライブラリにコピーする
7、データベースを作成し、数をターゲットライブラリにインポートする
7)メインライブラリ実行:show master status;PositionとFileの値をメモする
8)ライブラリからの同期構成の構成
9)接続異常チェック、ログチェック、ログイン失敗.
10)マスターライブラリの再承認
11)起動後に同期エラーを報告し、FUNCTIONエラーであることを確認し、FUNCTIONをターゲットライブラリに導く必要がある.
12)関数のエクスポートとインポート
11)再検査状態正常
12)メインライブラリのロックを解除し、データの同期を開始する.
4、ベースリファレンス
START SLAVE; # ライブラリSTOP SLAVEを起動する;スレーブを閉じる
MASTER_LOG_FILE=‘mysql-bin.000001’,#マスターファイルと一致するMASTER_LOG_POS=833188576、#はメインライブラリPositionと一致する
同期のテスト
プライマリスレーブ同期遅延#プライマリスレーブ同期中はすべてのSQLがサーバから一度実行しなければならないためですが、プライマリサーバが更新操作を繰り返すと、遅延が発生すると、遅延が重くなる可能性が高くなります.この問題は完全に解決することはできないが、私たちはいくつかの措置を取って緩和することができる.
プライマリ・サーバが更新操作を担当するため、セキュリティに対する要求がサーバよりも高いことを知っています.syncなどの設定を変更することができます.binlog=1,innodb_flush_log_at_trx_commit=1のような設定ですが、slaveはこのような高いデータセキュリティを必要とせず、sync_を完全に話すことができます.binlogを0に設定するかbinlog,innodb_を閉じるflushlog, innodb_flush_log_at_trx_commitは、sqlの実行効率を向上させるために0に設定することもでき、これは効率を大幅に向上させることができる.また、メインライブラリよりも良いハードウェアデバイスをslaveとして使用します.
1、概要主従レプリケーション、主にデータベースのデータセキュリティを実現し、IO性能と読み書き分離機能を向上させ、主データベースと一致するデータベース環境を構築する.データベースからマルチレベルのレプリケーションを実行できます.2、mysqlコピーのタイプ1.STATEMENTモード(SBR)は、データを変更するsql文ごとにbinlogに記録されます.利点は、各sql文と各行のデータ変化を記録する必要がなく、binlogログ量を削減し、IOを節約し、パフォーマンスを向上させることです.欠点は、場合によってはmaster-slaveのデータが一致しない(sleep()関数、last_insert_id()やuser-defined functions(udf)などで問題が発生します)
ROWモード(RBR)は、各sql文のコンテキスト情報を記録せず、どのデータが修正され、どのように修正されたかを記録するだけです.また、特定の場合のストレージ・プロシージャ、またはfunction、またはtriggerの呼び出しやトリガが正しくコピーされないという問題は発生しません.欠点は、大量のログが発生し、特にalter tableの場合、ログが急騰することです.
MIXEDモード(MBR)以上の2つのモードが混在して使用され、一般的なレプリケーションではSTATEMENTモードでbinlogが保存され、STATEMENTモードではコピーできない操作ではROWモードでbinlogが保存され、MySQLでは実行するSQL文に基づいてログ保存方式が選択されます.
3、同期原理1.Masterデータベースは変更が発生するとすぐにBinaryログファイルに記録する.SlaveデータベースはI/O thread接続Masterデータベースを起動し、Master変化のバイナリログ3を要求する.Slave I/Oで取得したバイナリログは、自分のRelayログファイルに保存されます.4.Slave SQL threadのタイミングでRealy logが変化しているかどうかをチェックし、変化したらデータを更新する
2、mysqlインストール
プライマリ・スレーブを構成する前に、プライマリ・スレーブのmysqlデータベースをインストールする必要があります.インストール方法は同じです.1、インストールパッケージをダウンロードしてサーバーにアップロードし、mysqlディレクトリに解凍する.
[root@host-10-253-234-32 soft]# tar -xvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
[root@host-10-253-234-32 soft]# ls
mysql-5.7.31-linux-glibc2.12-x86_64 mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
[root@host-10-253-234-32 soft]#
[root@host-10-253-234-32 ~]# mv /soft/mysql-5.7.31-linux-glibc2.12-x86_64 /u01/mysql5.7
2、mysqlユーザーを作成し、授権する.
[root@host-10-253-234-32 ~]# useradd -r -s /sbin/nologin mysql
chown -R mysql:mysql /u01/mysql5.7
[root@host-10-253-234-32 ~]# chown -R mysql:mysql /u01/mysql5.7
[root@host-10-253-234-32 mysql5.7]#
3、配置my.cnfファイル
vi /etc/my.cnf
[root@host-10-253-234-32 mysql5.7]# cp /etc/my.cnf /etc/my.cnf.bak
[root@host-10-253-234-32 mysql5.7]# vi /etc/my.cnf
[root@host-10-253-234-32 mysql5.7]# more /etc/my.cnf
[client]
socket=/u01/mysql5.7/mysql.sock
[mysqld]
user=mysql
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_allowed_packet=20M
max_connections=1000
lower_case_table_names=1
basedir=/u01/mysql5.7
datadir=/u01/mysql5.7/data
socket=/u01/mysql5.7/mysql.sock
character_set_server=utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#[mysqld_safe]
log-error=/u01/mysql5.7/log/mysql.err
pid-file=/u01/mysql5.7/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@host-10-253-234-32 mysql5.7]#
4、インストールして、そしてランダムに生成したパスワードを覚えて、初めてログインして使う必要があります
[root@host-10-253-234-32 mysql5.7]#
[root@host-10-253-234-32 mysql5.7]# bin/mysqld --initialize --user=mysql --basedir=/u01/mysql5.7 --datadir=/u01/mysql5.7/data
2020-07-18T01:35:21.513029Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-07-18T01:35:21.720049Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-07-18T01:35:21.762184Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-07-18T01:35:21.821359Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f1f4a61a-c896-11ea-8c77-fa163eae1a0e.
2020-07-18T01:35:21.822556Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-07-18T01:35:22.614278Z 0 [Warning] CA certificate ca.pem is self signed.
2020-07-18T01:35:22.924924Z 1 [Note] A temporary password is generated for root@localhost: Dc(hW5-o>JoN
[root@host-10-253-234-32 mysql5.7]#
5、ssl暗号化
bin/mysql_ssl_rsa_setup --datadir=/u01/mysql5.7
6の構成、mysql起動サービスの構成[root@host-10-253-234-32 mysql5.7]# ln -s /mysql/bin/mysql /usr/bin
[root@host-10-253-234-32 mysql5.7]# cp support-files/mysql.server /etc/init.d/mysql
[root@host-10-253-234-32 mysql5.7]# chkconfig --add mysql
[root@host-10-253-234-32 mysql5.7]# chkconfig mysql on
[root@host-10-253-234-32 mysql5.7]# chkconfig --list mysql
7、サービスを開始する
/etc/init.d/mysql start
service start mysql #linux 6
systemctl start mysql #linux 7
8、自動生成されたパスワードDc(hW 5-o>JoNを使用してデータベースにログインし、rootパスワードを変更し、設定を変更してリモートログインを許可する.そうしないとERROR 1820(HY 000):You must reset your password using ALTER USER statement before executing this statement
[root@host-10-253-234-32 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47966
Server version: 5.7.31-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> set password=password('password@1316');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on *.* to root@'%' identified by 'password@1316';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
3、主従同期の構成
1)マスターライブラリ構成my.cnf、次のパラメータを追加
#Master config
server_id=1
log_bin=mysql-bin
binlog_format=MIXED
binlog_ignore_db=information_schema,mysql,performance_schema,sys
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#[mysqld_safe]
log-error=/u01/mysql5.7/log/mysql.err
pid-file=/u01/mysql5.7/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
2)マスターライブラリの構成
[[client]
socket=/u01/mysql5.7/mysql.sock
[mysqld]
user=mysql
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_allowed_packet=20M
max_connections=1000
lower_case_table_names=1
basedir=/u01/mysql5.7
datadir=/u01/mysql5.7/data
socket=/u01/mysql5.7/mysql.sock
character_set_server=utf8
#Master config
server_id=1
log_bin=mysql-bin
binlog_format=MIXED
binlog_ignore_db=information_schema,mysql,performance_schema,sys
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#[mysqld_safe]
log-error=/u01/mysql5.7/log/mysql.err
pid-file=/u01/mysql5.7/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
#
[root@host-10-253-234-32 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 46967
Server version: 5.7.31-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 0 |
+------------------+-------+
1 row in set (0.00 sec)
mysql>
mysql> set global expire_logs_days=15;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 15 |
+------------------+-------+
1 row in set (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
3)再起動、マスターライブラリ作成同期ユーザslave
[root@host-10-253-234-32 openssh-8.2p1]# systemctl stop mysql
[root@host-10-253-234-32 openssh-8.2p1]# systemctl start mysql
[root@host-10-253-234-32 openssh-8.2p1]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 123
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%' identified by 'JY19MZslave';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> set password=password('PASSWORD');
mysql> grant all privileges on *.* to root@'%' identified by 'PASSWORD';
4)スレーブmyを設定する.cnf
[root@host-10-253-234-33 ~]# more /etc/my.cnf
[client]
socket=/u01/mysql5.7/mysql.sock
[mysqld]
user=mysql
basedir=/u01/mysql5.7
datadir=/u01/mysql5.7/data
socket=/u01/mysql5.7/mysql.sock
character_set_server=utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
server_id=2
log_bin=mysql-bin
binlog_format=MIXED
relay_log_recovery=1
#[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
log-error=/u01/mysql5.7/log/mysql.err
pid-file=/u01/mysql5.7/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
mysql> set global expire_logs_days=15;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 15 |
+------------------+-------+
1 row in set (0.00 sec)
mysql>
5)マスター・ライブラリ・データの同期ソース・ライブラリ・データのエクスポート
[root@host-10-253-234-32 ~]# /u01/mysql5.7/bin/mysqldump -uroot -p cloudstore>/tmp/cloudstore.sql;
Enter password:
[root@host-10-253-234-32 ~]# /u01/mysql5.7/bin/mysqldump -uroot -p gaassc>/tmp/gaassc.sql;
Enter password:
[root@host-10-253-234-32 ~]# /u01/mysql5.7/bin/mysqldump -uroot -p intelligentsuperisiondb>/tmp/intelligentsuperisiondb.sql;
Enter password:
[root@host-10-253-234-32 ~]# /u01/mysql5.7/bin/mysqldump -uroot -p szyzt>/tmp/szyzt.sql;
Enter password:
[root@host-10-253-234-32 ~]# /u01/mysql5.7/bin/mysqldump -uroot -p yhucmmg>/tmp/yhucmmg.sql;
Enter password:
[root@host-10-253-234-32 ~]# /u01/mysql5.7/bin/mysqldump -uroot -p zsk>/tmp/zsk.sql;
Enter password:
[root@host-10-253-234-32 ~]#
6)マスターライブラリからエクスポートされたデータファイルをターゲットライブラリにコピーする
[root@host-10-253-234-32 tmp]# scp *.sql root@10.253.234.33:/tmp
root@10.253.234.33's password:
cloudstore.sql 100% 498KB 51.0MB/s 00:00
szmzyl.sql 100% 682MB 110.9MB/s 00:06
szyzt.sql 100% 548MB 109.8MB/s 00:04
yhucmmg.sql 100% 96MB 119.5MB/s 00:00
zsk.sql 100% 617MB 108.6MB/s 00:05
7、データベースを作成し、数をターゲットライブラリにインポートする
[root@host-10-253-234-33 mysql5.7]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.31-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database cloudstore;
Query OK, 1 row affected (0.00 sec)
mysql> create database szmzyl;
Query OK, 1 row affected (0.00 sec)
mysql> create database szyzt;
Query OK, 1 row affected (0.01 sec)
mysql> create database yhucmmg;
Query OK, 1 row affected (0.00 sec)
mysql> create database zsk;
Query OK, 1 row affected (0.00 sec)
mysql> exit
Bye
[root@host-10-253-234-33 ~]# mysql -u root -p zsk < /tmp/zsk.sql;
Enter password:
[root@host-10-253-234-33 ~]# ls -l /tmp
-rw-r--r--. 1 root root 510339 7 30 22:26 /tmp/cloudstore.sql
-rw-r--r--. 1 root root 714921360 7 30 21:53 /tmp/szmzyl.sql
-rw-r--r--. 1 root root 574854723 7 30 21:53 /tmp/szyzt.sql
-rw-r--r--. 1 root root 100624706 7 30 21:53 /tmp/yhucmmg.sql
-rw-r--r--. 1 root root 647413712 7 30 21:53 /tmp/zsk.sql
[root@host-10-253-234-33 ~]# mysql -u root -p szyzt < /tmp/szyzt.sql;
Enter password:
[root@host-10-253-234-33 ~]#
7)メインライブラリ実行:show master status;PositionとFileの値をメモする
mysql> show master status;
+------------------+-----------+--------------+-------------------------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+-----------+--------------+-------------------------------------------------+-------------------+
| mysql-bin.000001 | 833188576 | | information_schema,mysql,performance_schema,sys | |
+------------------+-----------+--------------+-------------------------------------------------+-------------------+
1 row in set (0.00 sec)
8)ライブラリからの同期構成の構成
[root@host-10-253-234-33 ~]# systemctl stop mysql
[root@host-10-253-234-33 ~]# systemctl start mysql
[root@host-10-253-234-33 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> change master to
-> master_host='10.253.234.32', # IP
-> master_user='slave', #
-> master_password='JY19MZslave', #
-> master_port=3306,
-> master_log_file='mysql-bin.000001', #7 log_file
-> master_log_pos=833188576; #7 log_pos
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> SHOW SLAVE STATUS;
+----------------+---------------+-------------+-------------+---------------+------------------+---------------------+-------------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+-------------+--------------------------------+-----------+---------------------+-------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno | Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID | Master_Info_File | SQL_Delay | SQL_Remaining_Delay | Slave_SQL_Running_State | Master_Retry_Count | Master_Bind | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp | Master_SSL_Crl | Master_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position | Replicate_Rewrite_DB | Channel_Name | Master_TLS_Version |
+----------------+---------------+-------------+-------------+---------------+------------------+---------------------+-------------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+-------------+--------------------------------+-----------+---------------------+-------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+
| | 10.253.234.32 | slave | 3306 | 60 | mysql-bin.000001 | 833188576 | host-10-253-234-33-relay-bin.000001 | 4 | mysql-bin.000001 | No | No | | | | | | | 0 | | 0 | 833188576 | 154 | None | | 0 | No | | | | | | NULL | No | 0 | | 0 | | | 0 | | /u01/mysql5.7/data/master.info | 0 | NULL | | 86400 | | | | | | | | 0 | | | |
+----------------+---------------+-------------+-------------+---------------+------------------+---------------------+-------------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+-------------+--------------------------------+-----------+---------------------+-------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+
1 row in set (0.00 sec)
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 10.253.234.32
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 833188576
Relay_Log_File: host-10-253-234-33-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 833188576
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 1045
Last_IO_Error: error connecting to master '[email protected]:3306' - retry-time: 60 retries: 1
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: /u01/mysql5.7/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp: 200719 11:52:30
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
9)接続異常チェック、ログチェック、ログイン失敗.
[root@host-10-253-234-33 log]# tail -f mysql.err
2020-07-19T03:57:30.125046Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 6, Error_code: 1045
2020-07-19T03:58:30.126947Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 7, Error_code: 1045
2020-07-19T03:59:30.128985Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 8, Error_code: 1045
2020-07-19T04:00:30.130947Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 9, Error_code: 1045
2020-07-19T04:01:30.134093Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 10, Error_code: 1045
2020-07-19T04:02:30.135890Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 11, Error_code: 1045
2020-07-19T04:03:30.139051Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 12, Error_code: 1045
2020-07-19T04:04:30.140825Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 13, Error_code: 1045
2020-07-19T04:05:30.142791Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 14, Error_code: 1045
2020-07-19T04:06:30.144744Z 3 [ERROR] Slave I/O for channel '': error connecting to master '[email protected]:3306' - retry-time: 60 retries: 15, Error_code: 1045
2020-07-19T04:07:30.146501Z 3 [Note] Slave I/O thread for channel '': connected to master '[email protected]:3306',replication started in log 'mysql-bin.000001' at position 833188576
[root@host-10-253-234-33 log]# mysql -u slave -h 10.253.234.32 -p
Enter password:
ERROR 1045 (28000): Access denied for user 'slave'@'10.253.234.33' (using password: YES)
10)マスターライブラリの再承認
mysql> grant replication slave on *.* to 'slave'@'%' identified by 'JY19MZslave';
ERROR 1223 (HY000): Can't execute the query because you have a conflicting read lock
mysql> unlock table;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to 'slave'@'%' identified by 'JY19MZslave';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql>
11)起動後に同期エラーを報告し、FUNCTIONエラーであることを確認し、FUNCTIONをターゲットライブラリに導く必要がある.
mysql> start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.253.234.32
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 65236
Relay_Log_File: host-10-253-234-33-relay-bin.000004
Relay_Log_Pos: 137222651
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1305
Last_Error: Error 'FUNCTION yhucmmg.seq does not exist' on query. Default database: 'yhucmmg'. Query: 'SELECT `yhucmmg`.`seq`(_utf8'SEQ_FILEINFO' COLLATE 'utf8_general_ci')'
Skip_Counter: 0
Exec_Master_Log_Pos: 970410907
Relay_Log_Space: 7093622466
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1305
Last_SQL_Error: Error 'FUNCTION yhucmmg.seq does not exist' on query. Default database: 'yhucmmg'. Query: 'SELECT `yhucmmg`.`seq`(_utf8'SEQ_FILEINFO' COLLATE 'utf8_general_ci')'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: f1f4a61a-c896-11ea-8c77-fa163eae1a0e
Master_Info_File: /u01/mysql5.7/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 200726 23:25:54
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
12)関数のエクスポートとインポート
#
[root@host-10-253-234-32 tmp]# /u01/mysql5.7/bin/mysqldump -u root -p --databases szmzyl -ntdR --triggers=false > /tmp/szmzylf.sql
Enter password:
[root@host-10-253-234-32 tmp]# /u01/mysql5.7/bin/mysqldump -u root -p --databases cloudstore -ntdR --triggers=false > /tmp/cloudstoref.sql
Enter password:
[root@host-10-253-234-32 tmp]# /u01/mysql5.7/bin/mysqldump -u root -p --databases szyzt -ntdR --triggers=false > /tmp/szyztf.sql
Enter password:
[root@host-10-253-234-32 tmp]# /u01/mysql5.7/bin/mysqldump -u root -p --databases yhucmmg -ntdR --triggers=false > /tmp/yhucmmgf.sql
Enter password:
[root@host-10-253-234-32 tmp]# /u01/mysql5.7/bin/mysqldump -u root -p --databases zsk -ntdR --triggers=false > /tmp/zskf.sql
Enter password:
[root@host-10-253-234-32 tmp]# scp *f.sql root@10.253.234.33:/tmp
root@10.253.234.33's password:
cloudstoref.sql 100% 2399 1.3MB/s 00:00
szmzylf.sql 100% 22KB 13.9MB/s 00:00
szyztf.sql 100% 1358 1.8MB/s 00:00
yhucmmgf.sql 100% 2384 3.1MB/s 00:00
zskf.sql 100% 2333 2.8MB/s 00:00
[root@host-10-253-234-32 tmp]#
#
[root@host-10-253-234-33 ~]# mysql -u root -p yhucmmg < /tmp/fyhucmmg.log;
Enter password:
ERROR 1418 (HY000) at line 37: This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
[root@host-10-253-234-33 ~]#
[root@host-10-253-234-33 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 242
Server version: 5.7.31-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like 'log_bin_trust_function_creators';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | OFF |
+---------------------------------+-------+
1 row in set (0.00 sec)
mysql>
mysql> set global log_bin_trust_function_creators=TRUE;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#
[root@host-10-253-234-33 ~]# mysql -u root -p szmzyl < /tmp/szmzylf.sql
Enter password:
[root@host-10-253-234-33 ~]# mysql -u root -p szyzt < /tmp/szyztf.sql
Enter password:
[root@host-10-253-234-33 ~]# mysql -u root -p yhucmmg < /tmp/yhucmmgf.sql
Enter password:
[root@host-10-253-234-33 ~]# mysql -u root -p cloudstore < /tmp/cloudstoref.sql
Enter password:
[root@host-10-253-234-33 ~]# mysql -u root -p zsk < /tmp/zskf.sql
Enter password:
[root@host-10-253-234-33 ~]#
11)再検査状態正常
mysql> start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.253.234.32
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000012
Read_Master_Log_Pos: 576500579
Relay_Log_File: host-10-253-234-33-relay-bin.000002
Relay_Log_Pos: 9547
Relay_Master_Log_File: mysql-bin.000012
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 576500579
Relay_Log_Space: 9767
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: f1f4a61a-c896-11ea-8c77-fa163eae1a0e
Master_Info_File: /u01/mysql5.7/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql>
12)メインライブラリのロックを解除し、データの同期を開始する.
mysql> unlock table;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
4、ベースリファレンス
START SLAVE; # ライブラリSTOP SLAVEを起動する;スレーブを閉じる
MASTER_LOG_FILE=‘mysql-bin.000001’,#マスターファイルと一致するMASTER_LOG_POS=833188576、#はメインライブラリPositionと一致する
同期のテスト
プライマリスレーブ同期遅延#プライマリスレーブ同期中はすべてのSQLがサーバから一度実行しなければならないためですが、プライマリサーバが更新操作を繰り返すと、遅延が発生すると、遅延が重くなる可能性が高くなります.この問題は完全に解決することはできないが、私たちはいくつかの措置を取って緩和することができる.
プライマリ・サーバが更新操作を担当するため、セキュリティに対する要求がサーバよりも高いことを知っています.syncなどの設定を変更することができます.binlog=1,innodb_flush_log_at_trx_commit=1のような設定ですが、slaveはこのような高いデータセキュリティを必要とせず、sync_を完全に話すことができます.binlogを0に設定するかbinlog,innodb_を閉じるflushlog, innodb_flush_log_at_trx_commitは、sqlの実行効率を向上させるために0に設定することもでき、これは効率を大幅に向上させることができる.また、メインライブラリよりも良いハードウェアデバイスをslaveとして使用します.