MySQL8主从搭建
基础环境
基本信息:
虚拟化软件:Oracle VM VirtualBox
1C/2G
1个网卡
80G系统盘
oracle:mysql-8.0.20
yum:CentOS-7.6-x86_64-DVD-1810.iso
服务器IP规划:
主机名 | mysql1 | mysql 2 | mysql 3 |
---|---|---|---|
系统 | CentOS-7.6 | CentOS-7.6 | CentOS-7.6 |
IP | 192.168.56.41 | 192.168.56.42 | 192.168.56.43 |
操作系统配置
修改主机名
hostnamectl set-hostname mysql1
hostnamectl set-hostname mysql2
修改hosts文件
/etc/hosts
192.168.56.41 mysql1
192.168.56.42 mysql2
关闭防火墙和SELINUX
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
vim /etc/selinux/config #将SELINUX设置为disabled
配置网络
网卡:enp0s3
按照前期规划的服务器IP规划正常配置就行
配置本地yum
将CentOS-7.6-x86_64-DVD-1810.iso文件传到/iso文件夹
执行mount -t iso9660 -o loop /iso/CentOS-7.6-x86_64-DVD-1810.iso /mnt
创建
[oracle@bsgrac2:/etc/yum.repos.d]$vim Centos7.repo
[local]
name=Centos7
baseurl=file:///mnt
gpgcheck=0
enabled=1
yum clean all&&yum makecache
安装依赖
查看是否安装mariadb,有的话卸载
[root@mysql1 soft]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@mysql1 soft]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
检查依赖,没有的话需要安装
rpm -qa|grep libaio
rpm -qa|grep numactl
安装mysql
解压mysql包
cd /soft
tar -zxvf mysql-8.0.20-el7-x86_64.tar.gz
创建文件夹和授权目录
mkdir -p /usr/local/mysql
mv mysql-8.0.20-el7-x86_64/* /usr/local/mysql
cd /usr/local/mysql
mkdir data logs
groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
编辑my.cnf文件
vi /etc/my.cnf
[mysqld]
port = 3306
server-id = 41
user = mysql
socket = /tmp/mysql.sock
# 安装目录
basedir=/usr/local/mysql
# 数据存放目录
datadir=/usr/local/mysql/data
log-bin=/usr/local/mysql/logs/mysql-bin
innodb_data_home_dir =/usr/local/mysql/data
innodb_log_group_home_dir =/usr/local/mysql/data
#日志及进程数据的存放目录
log-error=/usr/local/mysql/logs/mysql.log
pid-file =/usr/local/mysql/data/mysql.pid
slow_query_log=1
slow_query_log_file=/usr/local/mysql/logs/slow.log
long_query_time=0.1
log_queries_not_using_indexes=1
安装初始化数据库,生成密码
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
[root@mysql1 logs]# cat /usr/local/mysql/logs/mysql.log |grep pass
2024-05-29T06:10:36.259908Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: KadcpFZ%T2p#
配置mysql服务
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 65536
LimitNPROC = 65536
systemctl daemon-reload ##重新加载 systemctl
添加软连接
[root@mysql1 logs]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[root@mysql1 logs]# ln -s /usr/local/mysql/bin/mysqldump /usr/bin/
开启mysql数据库
[root@mysql1 logs]# systemctl start mysqld
[root@mysql1 logs]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2024-05-29 14:15:32 CST; 12s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 13993 (mysqld)
Tasks: 39
CGroup: /system.slice/mysqld.service
└─13993 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
May 29 14:15:32 mysql1 systemd[1]: Started MySQL Server.
修改root用户密码
[root@mysql1 logs]# mysql -u root -p
mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘bsg123’;
Query OK, 0 rows affected (0.00 sec)
改成远程连接update user set host=‘%’ where user=‘root’;
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
离线创建GTID主从复制
创建复制用户
mysql> create user ‘repl’@‘%’ identified with mysql_native_password by ‘bsg_123’;
Query OK, 0 rows affected (0.01 sec)
mysql> grant replication slave on *.* to ‘repl’@‘%’;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
查看用户
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select Host,User,plugin from user;
±----------±-----------------±----------------------+
| Host | User | plugin |
±----------±-----------------±----------------------+
| % | repl | mysql_native_password |
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
±----------±-----------------±----------------------+
5 rows in set (0.00 sec)
打开gtid,mysql1和mysql2都需要做
vi /etc/my.cnf
#末尾添加
开启gtid模式
gtid_mode = on
#强制gtid一致性
enforce_gtid_consistency = on
检查用户是否可以登录
[root@mysql2 logs]# mysql -u repl -p -h 192.168.56.41
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.20 MySQL Community Server - GPL
Copyright © 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> quit
Bye
开启slave
mysql> change master to master_host=‘192.168.56.41’, master_user=‘repl’, master_password=‘bsg_123’, master_port=3306,master_auto_position = 1;
Query OK, 0 rows affected, 2 warnings (0.23 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.41
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 156
Relay_Log_File: mysql2-relay-bin.000002
Relay_Log_Pos: 371
Relay_Master_Log_File: mysql-bin.000004
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: 156
Relay_Log_Space: 581
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: 41
Master_UUID: 29fbefde-1d82-11ef-972b-080027fadd9d
Master_Info_File: mysql.slave_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: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set (0.00 sec)
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
io thread和sql thread两个均已开启完成
Seconds_Behind_Master: 0
验证同步结果
创建数据库bsg和表test
mysql1创建
mysql> create database bsg;
mysql> CREATE TABLE test (
-> id VARCHAR(100),
-> name VARCHAR(100));
Query OK, 0 rows affected (0.27 sec)
mysql2查询
mysql> show databases;
±-------------------+
| Database |
±-------------------+
| bsg |
| information_schema |
| mysql |
| performance_schema |
| sys |
±-------------------+
5 rows in set (0.00 sec)
mysql> use bsg
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
±--------------+
| Tables_in_bsg |
±--------------+
| test |
±--------------+
1 row in set (0.01 sec)
在线创建GTID主从复制
mysql主库检查为开启状态
[root@mysql2 soft]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2024-05-29 14:34:24 CST; 2h 42min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 2530 (mysqld)
Tasks: 44
CGroup: /system.slice/mysqld.service
└─2530 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
从库上执行在线GTID
开启gtid一致性
mysql> set global ENFORCE_GTID_CONSISTENCY = ON;
Query OK, 0 rows affected (0.00 sec)
开启GTID_MODE宽松模式
mysql> set global GTID_MODE = ON_PERMISSIVE;
Query OK, 0 rows affected (0.22 sec)
检查有无事务没有结束
mysql> SHOW STATUS LIKE ‘ONGOING_ANONYMOUS_TRANSACTION_COUNT’;
±------------------------------------±------+
| Variable_name | Value |
±------------------------------------±------+
| Ongoing_anonymous_transaction_count | 0 |
±------------------------------------±------+
1 row in set (0.00 sec)
检查从库状态
mysql> show slave status\G;
Empty set (0.00 sec)
ERROR:
No query specified
开启全局GTID_MODE
mysql> set global GTID_MODE = ON;
Query OK, 0 rows affected (0.03 sec)
停止slave
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
添加向主库同步的账号开启实时同步
mysql> change master to master_host=‘192.168.56.42’, master_user=‘repl2’, master_password=‘bsg123’, master_port=3306,master_auto_position = 1;
Query OK, 0 rows affected, 2 warnings (0.35 sec)
开启slave
mysql> start slave;
Query OK, 0 rows affected (0.03 sec)
检查slave状态
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.42
Master_User: repl2
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 6961
Relay_Log_File: mysql3-relay-bin.000002
Relay_Log_Pos: 7176
Relay_Master_Log_File: mysql-bin.000004
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: 6961
Relay_Log_Space: 7386
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: 42
Master_UUID: 7668155c-1d82-11ef-94dc-0800273a2bb9
Master_Info_File: mysql.slave_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: 29fbefde-1d82-11ef-972b-080027fadd9d:1-10,
7668155c-1d82-11ef-94dc-0800273a2bb9:1-15
Executed_Gtid_Set: 29fbefde-1d82-11ef-972b-080027fadd9d:1-10,
7668155c-1d82-11ef-94dc-0800273a2bb9:1-15
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set (0.00 sec)
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
io thread和sql thread两个均已开启完成
Seconds_Behind_Master: 0
完成GTID模式后,需要在my.cnf文件添加
gtid_mode = on
enforce_gtid_consistency = on
验证结果
mysql2主库插入一条数据
mysql> INSERT INTO bsg.test
-> (id, name)
-> VALUES(‘4’, ‘bao’);
Query OK, 1 row affected (0.01 sec)
mysql3查询bsg.test表验证
mysql> select * from test;
±-----±-----+
| id | name |
±-----±-----+
| 1 | q |
| 2 | w |
| 3 | e |
| 4 | bao |
±-----±-----+
同步完成
主从切换
mysql1和mysql2设置只读模式
mysql> set global read_only=ON;
Query OK, 0 rows affected (0.00 sec)
mysql> set global super_read_only=ON;
Query OK, 0 rows affected (0.01 sec)
查看备库复制进程状态
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.41
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 2832
Relay_Log_File: mysql2-relay-bin.000002
Relay_Log_Pos: 3047
Relay_Master_Log_File: mysql-bin.000004
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: 2832
Relay_Log_Space: 3257
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: 41
Master_UUID: 29fbefde-1d82-11ef-972b-080027fadd9d
Master_Info_File: mysql.slave_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: 29fbefde-1d82-11ef-972b-080027fadd9d:1-10
Executed_Gtid_Set: 29fbefde-1d82-11ef-972b-080027fadd9d:1-10
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set (0.00 sec)
状态正常
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
比对主备两边的GTID是否一致
mysql1:
mysql> select @@global.gtid_executed;
±------------------------------------------+
| @@global.gtid_executed |
±------------------------------------------+
| 29fbefde-1d82-11ef-972b-080027fadd9d:1-10 |
±------------------------------------------+
1 row in set (0.00 sec)
mysql2:
mysql> select @@global.gtid_executed;
±------------------------------------------+
| @@global.gtid_executed |
±------------------------------------------+
| 29fbefde-1d82-11ef-972b-080027fadd9d:1-10 |
±------------------------------------------+
1 row in set (0.00 sec)
mysql1和mysql2的gtid一致
从库停掉复制进程清空主从信息取消只读
mysql> stop slave;
Query OK, 0 rows affected (0.01 sec)
mysql> reset slave all;
Query OK, 0 rows affected (0.04 sec)
mysql> set global read_only=OFF;
Query OK, 0 rows affected (0.00 sec)
mysql> set global super_read_only=OFF;
Query OK, 0 rows affected (0.00 sec)
创建复制用户
mysql> create user ‘repl2’@‘%’ identified with mysql_native_password by ‘bsg123’;
Query OK, 0 rows affected (0.01 sec)
mysql> grant replication slave,replication client on *.* to ‘repl2’@‘%’;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql1验证用户
[root@mysql1 ~]# mysql -u repl2 -p -h 192.168.56.42
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.20 MySQL Community Server - GPL
Copyright © 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> quit
Bye
原主库变为从库,并取消只读
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> change master to master_host=‘192.168.56.42’, master_user=‘repl2’, master_password=‘bsg123’, master_port=3306,master_auto_po
sition = 1;Query OK, 0 rows affected, 2 warnings (0.05 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
查看现从库mysql1状态
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.56.42
Master_User: repl2
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 3546
Relay_Log_File: mysql1-relay-bin.000002
Relay_Log_Pos: 1111
Relay_Master_Log_File: mysql-bin.000004
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: 3546
Relay_Log_Space: 1321
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: 42
Master_UUID: 7668155c-1d82-11ef-94dc-0800273a2bb9
Master_Info_File: mysql.slave_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: 7668155c-1d82-11ef-94dc-0800273a2bb9:1-3
Executed_Gtid_Set: 29fbefde-1d82-11ef-972b-080027fadd9d:1-10,
7668155c-1d82-11ef-94dc-0800273a2bb9:1-3
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set (0.00 sec)
查看状态
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
取消只读
mysql> set global read_only=off;
Query OK, 0 rows affected (0.00 sec)
mysql> set global super_read_only=off;
Query OK, 0 rows affected (0.00 sec)
主从切换完成
验证同步结果
mysql2向bsg.test表中插入一条数据
mysql> INSERT INTO bsg.test
-> (id, name)
-> VALUES(‘1’, ‘q’);
Query OK, 1 row affected (0.01 sec)
mysql1查询验证
mysql> select * from test;
±-----±-----+
| id | name |
±-----±-----+
| 1 | q |
±-----±-----+
1 row in set (0.00 sec)
同步完成
mysql将binlog转成sql
./mysqlbinlog -vv /usr/local/mysql/logs/mysql-bin.000004
选项:
-h, --host=:连接MySQL服务器的主机名。
-P, --port=<port_num>:连接MySQL服务器的端口号。
-u, --user=:连接MySQL服务器的用户名。
-p, --password=:连接MySQL服务器的密码。
–ssl-ca=<ca_file>:使用指定的CA证书文件进行SSL连接。
–ssl-cert=<cert_file>:使用指定的SSL证书文件进行SSL连接。
–ssl-key=<key_file>:使用指定的SSL密钥文件进行SSL连接。
-R, --read-from-remote-server:从远程MySQL服务器读取二进制日志。
-r, --result-file=<file_name>:将解析后的日志输出到指定的文件。
–base64-output[=value]:将blob字段以Base64编码的形式输出。
-v, --verbose:详细输出解析后的日志内容。
-d, --database=<database_name>:仅输出指定数据库的日志内容。
-t, --to-last-log:从当前日志文件开始读取,直到最新的日志文件结束。
-s, --start-datetime=:从指定的日期和时间开始读取日志。
-e, --stop-datetime=:在指定的日期和时间停止读取日志。
–start-position=:从指定的位置开始读取日志。
–stop-position=:在指定的位置停止读取日志。
–skip-gtids[=value]:跳过指定的GTID(全局事务标识符)。
–include-gtids[=value]:仅包括指定的GTID。
–hexdump:以十六进制格式输出日志内容。
–no-defaults:不读取默认的配置文件。
mysql开启审计日志
mysql> show variables like ‘%general_log%’;
±-----------------±---------------------------------+
| Variable_name | Value |
±-----------------±---------------------------------+
| general_log | OFF |
| general_log_file | /usr/local/mysql/data/mysql1.log |
±-----------------±---------------------------------+
2 rows in set (0.00 sec)
mysql> set global general_log=on
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like ‘%general_log%’;
±-----------------±---------------------------------+
| Variable_name | Value |
±-----------------±---------------------------------+
| general_log | ON |
| general_log_file | /usr/local/mysql/data/mysql1.log |
±-----------------±---------------------------------+
2 rows in set (0.00 sec)
标签:rows,Log,MySQL8,SSL,sec,mysql,Master,主从,搭建 From: https://blog.csdn.net/kkkbbbsg/article/details/142639774