mysql 管理ステートメントと関連するバックアップとリカバリ

1. データベース バックアップ ステートメント
1.1 フル バックアップ
xtrabackup --defaults-file=/usr/local/mysql/mysql6606.cnf --user=$user --password=$passwd --port=$port --socket=$socket - -use-memory=4G --Parallel=4 --no-lock --backup --target-dir=$full_backup_dir
1.2 増分バックアップ
1.2.1 最初の増分
innobackupex --defaults-file=/usr/local /mysql/mysql6606 .cnf --user=root --password=123 --incremental --incremental-basedir=/backup/full /backup/inc1
1.2.2 秒増分
innobackupex --defaults-file=/usr /local/mysql/mysql6606。 cnf --user=root --password=123 --incremental --incremental-basedir=/backup/inc1 /backup/inc2
1.2.3 論理バックアップ
mysqldump -uroot -p -R -E --max-allowed-packet=256M --single-transaction --set-gtid-purged=OFF -P6606 -S/data/mysql_6606/mysql.sock --databases tybss_report >/ data/tybss_report0509.sql
1.2.4 一部の表
mysqldump -uroot -p -R -E --max-allowed-packet=256M --single-transaction --set-gtid-purged=OFF -P6606 - S/data/mysql_6606/mysql.sock panda_rcs --ignore-table=panda_rcs.match_event_info --ignore-table=panda_rcs.standard_sport_market_flowing --ignore-table=panda_rcs.rcs_standard_sport_market_sell_flowing --ignore-table=panda_rcs.bak_match_statistics_info_detail --ignore- table=panda_rcs.standard_sport_market_odds --ignore-table=panda_rcs.rcs_monitor_error_log --ignore-table=panda_rcs.standard_sport_market --ignore-table=panda_rcs.rcs_monitor_mq_info > ./panda_rcs.sql
1.2.5 のみ备份特定テーブルの表構造
mysqldump -uroot -p -R -E --max-allowed-packet=256M --single-transaction --set-gtid-purged=OFF -P6606 -S/data/mysql_6606/mysql.sock -d panda_rcs match_event_info standard_sport_market_flowing rcs_standard_sport_market_sell_flowing bak_match_statistics_info_detail standard_sport_market_odds rcs_monitor_error_log standard_sport_market rcs_monitor_mq_info match_statistics_info_flowing rcs_monitor_garbage_collector > table.sql

2. データベースのリカバリ
2.1 フルバックアップのリカバリ
xtrabackup --defaults-file=/usr/local/mysql/mysql6606.cnf --prepare --target-dir=$full_backup_dir
xtrabackup --defaults-file=/usr/local/mysql/ mysql6606.cnf --host=localhost --user=root --password=mysql123 --port=6606 --datadir=/data/mysql_6606 --copy-back --target-dir=/db_backup/pro_15/backup/6626 /full/20200618_053001
2.2 増分バックアップのリカバリ
2.2.1 フルバックアップ
innobackupex --apply-log --redo-only /backup/3306/full
2.2.2 最初のバックアップのマージ フル
innobackupex --apply-log --redo -only -- incremental-dir=/data/backup/inc1 /data/backup/full
2.2.3 2 番目のバックアップは最初の
innobackupex --apply-log --incremental-dir=/data/backup/inc2 / data/backup/full
2.2をマージします。 .4 最後の仕上げ
innobackupex --apply-log /data/backup/full

3. ビンログ インターセプト
show master status
show binlog events in 'mybinlog.****'
SHOW BINLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count]
3.1 ノードの binlog をインターセプトし、このセクションをインターセプトしますgtid グループの操作。--exclude-gtids は gtid を除外します。この後に複数の binlog ファイルが続く場合があります。
mysqlbinlog --skip-gtids --include-gtids='1afe8136-601d-11e9-9022-000c2928f5dd:7-9' --exclude-gtids='dff98809-55c3-11e9-a58b-000c2928f5dd:4' /data/binlog /mysql-bin.000009 >/data/backup/binlog.sql
3.2
場所に従って mysqlbinlog をインターセプト --start-position=219 --stop-position=1347 /data/binlog/mysql-bin.000003 >/tmp/ bin.sql
3.3
時間に従って mysqlbinlog をインターセプト --start-datetime='2019-05-06 17:00:00' --stop-datetime='2019-05-06 17:01:00' /data/binlog/ mysql-bin .000004
3.4 バイナリログの表示
mysqlbinlog --defaults-file=/usr/local/mysql/mysql6606.cnf --start-datetime='2020-05-01 19:00:00' --stop-datetime='2020-05-01 19:10 :00' --base64-output=decode-rows -v mybinlog.000009 > /tmp/8.sql

4. 主从复制
use mysql;select * from smile_master_info;
スレーブを停止します。
スレーブをすべてリセットします。
マスターを master_host='10.5.11.21'、master_user='repl'、master_port=6606、master_password='RwFdd6ZpoKcfD07VgyHr'、master_auto_position=1 に変更します。
スレーブを開始します。

5. ceph挂ダウンロードdb_backup
mount -t ceph 10.5.17.202:6789:/ /db_backup -o name=admin,secretfile=./admin.key

6. データベースの起動とシャットダウン
6.1 サービス
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/mysql6606.cnf の開始 & 6.2
サービス
mysqladmin -uroot -p -S /data/mysql_6606の終了/mysql.sock のシャットダウン

6. マスターとスレーブの不一致により、GTID 操作をスキップする必要があります
。 スレーブ:
stop スレーブ;
set @@session.gtid_next='ed41df0a-05dc-11ea-a4b0-000c293a9237:520485'
begin;commit;
set @@session.gtid_next='automatic' ;

7. スローログ、クエリ番号とクエリ行番号で
ソート mysqldumpslow -s cr throw.log

8. ユーザー管理:
8.1 ユーザーの作成
create user test@'%' ('123' で識別);
Grant select on *.* to test@'%';
8.2 パスワードの変更
alter user test@'%' ('456' で識別)
8.3ユーザー権限の表示
root@'localhost' の付与を表示;
8.4 権限のキャンセル
revoke on *.* from test@'%';

9. デッドロック管理コマンド:
9.1 デッドロック ステータスの表示
show status like 'innodb_row_lock%';
9.2 ロック ソースの表示
use sys
select locked_table,waiting_trx_id,waiting_pid,blocking_trx_id,blocking_pid from innodb_lock_waits\G
9.3 ロック ソース ID の検索
select thread_id from Performance _schema. thread where processlist_id=25;
9.4 ロック ソースの SQL ステートメントを検索します。
select * from Performance_schema.events_statements_current where thread_id=65\G

10. cetus 管理
10.1 start
/usr/local/cetus/bin/cetus --defaults-file=/usr/local/cetus/conf/proxy.conf &
10.2 管理インターフェイス
/usr/bin/mysql -h10.5.22.42 -uadmin -P9606 -pRt57qHm8Xp91aFo3uExD
select * from backends 10.3 /usr/bin/mysql の書き込みと読み取りを
手動で切り替える-h10.5.22.42 -uadmin -P9606 -pRt57qHm8Xp91aFo3uExD -e " update backends set state='up' , type='
rw' アドレス = '10.5.22.41:6616';"

11. バイナリログを削除します
mysql> show master logs;
+------+------------+------ - ----+
| ログ名 | ファイルサイズ | 暗号化 |
+------+------------+----- -----+
| mybinlog.004356 | 1073742346 | no |
| mybinlog.004357 |
1073749103 |
no |
| mybinlog.004358 | 0 | 554989663 | no |
| mybinlog.004361 | 107341982
| | | 1073743396 | いいえ | | mybinlog.004363
| 1073769737 |いいえ | | 1073755841 | いいえ | | mybinlog.004366 | 1073742882 | いいえ | | mybinlog.004367 | 1073780415 | いいえ |




| mybinlog.004368 | 1073743509 | いいえ |
| mybinlog.004369 | 1073741875 | いいえ |

現在の binlog ログ ファイルを表示します。
mysql> show master status;'
+------+-----------+------ - -------+-----------------+---------------------- - ------------------------+
| ファイル | 位置 | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------- - --------+----------+--------------+--------------- - ----+-------------------------------------------- - ------+
| mybinlog.004385 | 115387258 | | | 31654e9c-1197-11ea-8f74-000c29d32f03:1-4466952829 |
+------+ - ----------+--------------+----------------------------+---- -----------------------------------------------+

バイナリ ログを削除
mysql> バイナリ ログを 'mybinlog.004383' にパージします。


12. データベース
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/opt/app1/data/mysql_6666 を初期化します。

1. mysql にログインして binlog を表示し
、最初の binlog ファイルの内容のみを表示します
mysql> show binlog events;
指定した binlog ファイルの内容を表示します
mysql> show binlog events in 'mysql-bin.000002';
get binlog ファイルのリスト
mysql> show binary logs;
フィルタリングする必要がある場合、挿入、更新、削除ステートメントのみをクエリする必要がある場合は、次のように記述できます:
mysqlbinlog --no-defaults --database=raceEnroll binlogs.000078 |grep update |more
2017-09-17 07:21:09 から 2017-09-19 07:59:50 データベースが geeRunner の操作ログであることをクエリする必要がある場合は、次のコマンドを入力して予備の txt にデータを書き込みます。
mysqlbinlog --no-defaults --database=geeRunner --start-datetime="2017-09-17 07:21:09" --stop-datetime="2017-09-19 07:59:50" binlogs.000080 > sanjiaomao.txt
--insecure-registry 192.168.111.143:8088
データベースの実行頻度を表示します。
show [session|global] status;
このログイン以降のデータベース操作をクエリします。主に値の取得に関係します。
'Com_insert%' のようなセッション ステータスを表示;
'Com_select%' のような
セッション ステータスを表示 'Com_update%' のようなセッション ステータスを表示;
'Com_delete%' のようなセッション ステータスを表示;
データベース サービスの開始以降、主に次のようなデータベース操作をクエリします。値の取得は、
「Com_delete%」のようなグローバル ステータスを表示します。「
Com_insert%」
のようなグローバル ステータスを表示します。「Com_update%」の
ようなグローバル ステータスを表示します。「Com_select%」のようなグローバル ステータスを表示します。
データベース innodb エンジンからデータベース操作をクエリします。主に値の取得に関係する
'InnoDB_rows%' などのセッション ステータスを表示する、
'InnoDB_rows%' などのグローバル ステータスを表示する、
成功および失敗を含むデータベース接続の数を表示する
'connections' などのグローバル ステータスを表示する、
'connections' などのセッション ステータスを表示する;
データベースの稼働時間を秒単位で表示し、
「稼働時間」などのセッション ステータスを表示します。
「Uptime」などのグローバル ステータスを表示;
データベース内の完全なクエリの数を確認します
「Slow_queries」などのグローバル ステータスを表示します。

おすすめ

転載: blog.csdn.net/eagle89/article/details/129686228