m6米乐安卓版下载-米乐app官网下载
暂无图片
10

linux 环境搭建 mysql8.0.28 主从同步环境 -m6米乐安卓版下载

2473

首先在介绍mysql 主从时,我们来看看 db-engines 排行榜上四月数据库的变化,前三甲居然都有小幅度增长,相反增长迅猛的 pg 和 mongodb 有所减少,一个月的增长趋势说明不了问题,下图是从 13 年开始的趋势图,oracle 和 mysql 渐渐趋平,学习了解 mysql 还是很有必要的。下面开始进入正题。

图片.png

(图源:http://db-engines.com/en/ranking)

图片.png

主从复制的原理

图片.png

mysql的主从复制中主要有三个线程:master(binlog dump thread)、slave(i/o thread 、sql thread),master一条线程和slave中的两条线程。

(1)master服务器将数据的改变记录二进制binlog日志,当master上的数据发生改变时,则将其改变写入二进制日志中;
(2)slave服务器会在一定时间间隔内对master二进制日志进行探测其是否发生改变,如果发生改变,则开始一个i/othread请求master二进制事件
(3)同时主节点为每个i/o线程启动一个dump线程,用于向其发送二进制事件,并保存至从节点本地的中继日志中,从节点将启动sql线程从中继日志中读取二进制日志,在本地重放,使得其数据和主节点的保持一致,最后i/othread和sqlthread将进入睡眠状态,等待下一次被唤醒。

图片.png

(图源 深入浅出 mysql 数据库开发、优化与管理维护)

由于资源限制没有那么多机器,本次使用一台原先装过 oracle 和 ogg 的主机构建一主两从的mysql 环境,通过三个不同的端口 3306、3307、3308 加以区分。

一、系统准备

0、查看系统版本

cat /etc/redhat-release 
red hat enterprise linux server release 7.6 (maipo)

1、关闭防火墙

systemctl stop firewalld.service或者systemctl stop firewalld
systemctl disable firewalld.service或者systemctl disable firewalld
systemctl status firewalld  

2、关闭 selinux

getenforce 
setenforce 0
vim /etc/selinux/config
   
selinux=disabled
[root@ops-11gogg ~]# systemctl status firewalld  
? firewalld.service - firewalld - dynamic firewall daemon
   loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   active: inactive (dead)
     docs: man:firewalld(1)
[root@ops-11gogg ~]# getenforce 
disabled

3、/etc/hosts解析

示例如下

192.168.77.86     ops-11gogg

4、配置 yum 源,安装依赖 rpm 包

yum -y groupinstall "development tools"
yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c   make

5、清理系统环境

linux7 版本的系统默认自带安装了mariadb,需要先清理。

## 查询已安装的mariadb
rpm -qa |grep mariadb
或
yum list installed | grep mariadb
## 卸载mariadb包,文件名为上述命令查询出来的文件
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
yum -y remove mariadb-libs.x86_64 

图片.png

二、安装 mysql8.0.28

0、创建实例所需目录

本手册中 3306 为一个实例,如部署多实例请按照下面目录结构创建目录

--root用户操作:
mkdir -p /mysql/data/mysql3306
mkdir -p /mysql/app/
mkdir -p /mysql/conf/
mkdir -p /mysql/data/mysql3306/data/
mkdir -p /mysql/data/mysql3306/pid/
mkdir -p /mysql/data/mysql3306/socket/
mkdir -p /mysql/data/mysql3306/log/
mkdir -p /mysql/data/mysql3306/binlog/
mkdir -p /mysql/data/mysql3306/relaylog/
mkdir -p /mysql/data/mysql3306/slowlog/
mkdir -p /mysql/data/mysql3306/tmp/
mkdir -p /mysql/data/mysql3307
mkdir -p /mysql/data/mysql3307/data/
mkdir -p /mysql/data/mysql3307/pid/
mkdir -p /mysql/data/mysql3307/socket/
mkdir -p /mysql/data/mysql3307/log/
mkdir -p /mysql/data/mysql3307/binlog/
mkdir -p /mysql/data/mysql3307/relaylog/
mkdir -p /mysql/data/mysql3307/slowlog/
mkdir -p /mysql/data/mysql3307/tmp/
mkdir -p /mysql/data/mysql3308
mkdir -p /mysql/data/mysql3308/data/
mkdir -p /mysql/data/mysql3308/pid/
mkdir -p /mysql/data/mysql3308/socket/
mkdir -p /mysql/data/mysql3308/log/
mkdir -p /mysql/data/mysql3308/binlog/
mkdir -p /mysql/data/mysql3308/relaylog/
mkdir -p /mysql/data/mysql3308/slowlog/
mkdir -p /mysql/data/mysql3308/tmp/

图片.png

1、创建数据库用户和组

groupadd mysql
useradd -g mysql mysql
chown -r mysql:mysql /mysql
passwd mysql

图片.png

2、上传解压安装包并重命名

如下链接,选择相关的版本和系统。

https://dev.mysql.com/downloads/mysql/8.0.html
md5: 5be32f68d6859aace1eb61cea1d00bff 

图片.png

mysql用户操作:
cd /mysql/app
md5sum mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz  --检验 md5 值和上面一样,说明包无损
tar xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
mv  mysql-8.0.28-linux-glibc2.12-x86_64 mysql8.0.28

3、配置mysql用户环境变量

vim ~/.bash_profile
mysql_home=/mysql/app/mysql8.0.28
path=$path:$home/.local/bin:$home/bin:$mysql_home/bin
source ~/.bash_profile
which mysql 

图片.png

4、创建参数文件

由于是二进制文件安装,数据库参数文件需要自己配置,以下是简单的参数配置。其他参数可依照个人需求添加。

vim  my3306.cnf
[mysqld]
# basic settings #
server_id = 863306
basedir = /mysql/app/mysql8.0.28
datadir = /mysql/data/mysql3306/data/
socket = /mysql/data/mysql3306/socket/mysql3306.sock
pid_file = /mysql/data/mysql3306/pid/mysqld3306.pid
port = 3306
default-time_zone = ' 8:00'
character_set_server = utf8mb4
explicit_defaults_for_timestamp = 1
autocommit = 1
transaction_isolation = read-committed
secure_file_priv = "/mysql/data/mysql3306/tmp/"
max_allowed_packet = 64m
lower_case_table_names = 1
default_authentication_plugin = mysql_native_password
sql_mode = 'strict_trans_tables,no_zero_in_date,no_zero_date,error_for_division_by_zero,no_engine_substitution'
# connection #
back_log = 500
interactive_timeout = 300
wait_timeout = 300
lock_wait_timeout = 300
max_user_connections = 800
skip_name_resolve = 1
max_connections = 3000
max_connect_errors = 1000
#table cache performance settings
#table_open_cache = 1024
#table_definition_cache = 1024
#table_open_cache_instances = 16
#session memory settings #
#read_buffer_size = 16m
#read_rnd_buffer_size = 32m
#sort_buffer_size = 32m
#tmp_table_size = 64m
#join_buffer_size = 128m
#thread_cache_size = 256
# log settings #
slow_query_log = on
slow_query_log_file = /mysql/data/mysql3306/slowlog/slow3306.log
log_error = /mysql/data/mysql3306/log/mysqld3306.log
log_error_verbosity = 3
log_bin = /mysql/data/mysql3306/binlog/mysql_bin
log_bin_index = /mysql/data/mysql3306/binlog/mysql_binlog.index
# general_log_file = /data/mysql/mysql57_3306/generallog/general.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
#log_slow_slave_statements = 1
#expire_logs_days = 15
binlog_expire_logs_seconds = 2592000
long_query_time = 2
min_examined_row_limit = 100
log_throttle_queries_not_using_indexes = 1000
#log_bin_trust_function_creators = 1
log_slave_updates = 1
mysqlx_port = 33060
mysqlx_socket = /mysql/data/mysql3306/socket/mysqlx.sock
# innodb settings #
innodb_buffer_pool_size = 512m
#innodb_buffer_pool_instances = 16
innodb_log_buffer_size = 100m
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 4096
innodb_lock_wait_timeout = 20
innodb_io_capacity = 5000
innodb_io_capacity_max = 10000
innodb_flush_method = o_direct
innodb_log_file_size = 1g
innodb_log_files_in_group = 2
innodb_purge_threads = 4
innodb_thread_concurrency = 200
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 32m
innodb_write_io_threads = 16
innodb_read_io_threads = 16 
innodb_file_per_table = 1
innodb_stats_persistent_sample_pages = 64
innodb_autoinc_lock_mode = 2
innodb_online_alter_log_max_size = 1g
innodb_open_files = 4096
innodb_buffer_pool_dump_pct = 25
innodb_page_cleaners = 16
innodb_undo_log_truncate = 1
innodb_max_undo_log_size = 2g
innodb_purge_rseg_truncate_frequency = 128
innodb_flush_log_at_trx_commit = 1
# replication settings #
master_info_repository = table
relay_log_info_repository = table
sync_binlog = 1
binlog_format = row
gtid_mode = on
enforce_gtid_consistency = on
relay_log_recovery = 1
relay_log = /mysql/data/mysql3306/relaylog/relay.log
relay_log_index = /mysql/data/mysql3306/relaylog/mysql_relay.index
slave_parallel_type = logical_clock
slave_parallel_workers = 16
binlog_gtid_simple_recovery = 1
slave_preserve_commit_order = 1
binlog_rows_query_log_events = 1
slave_transaction_retries = 10
log_timestamps = system
report_host = 192.168.75.86
report_port = 3306

–report_host复制副本注册期间要报告给源库的复制副本的主机名或ip地址。此值显示在源服务器上显示副本的输出中。如果不希望复制副本向源注册,请将该值保留为未设置。

其他两节点参数文件my3307.cnf、my3308.cnf中将上述文件中的 3306 全部替换为 3307、3308 即可。

5、数据库初始化

mysql用户操作,注意同主机参数文件名my3306.cnf 各不相同,间隔约两分钟分别初始化三个 mysql 实例。

mysqld  --defaults-file=/mysql/conf/my3306.cnf --initialize --user=mysql --basedir=/mysql/app/mysql8.0.28  --datadir=/mysql/data/mysql3306/data
mysqld  --defaults-file=/mysql/conf/my3307.cnf --initialize --user=mysql --basedir=/mysql/app/mysql8.0.28  --datadir=/mysql/data/mysql3307/data
mysqld  --defaults-file=/mysql/conf/my3308.cnf --initialize --user=mysql --basedir=/mysql/app/mysql8.0.28  --datadir=/mysql/data/mysql3307/data

6、启动三个数据库实例

mysqld_safe --defaults-file=/mysql/conf/my3306.cnf --user=mysql &
mysqld_safe --defaults-file=/mysql/conf/my3307.cnf --user=mysql &
mysqld_safe --defaults-file=/mysql/conf/my3308.cnf --user=mysql &
--关闭数据库
mysqladmin -uroot -p -h 127.0.0.1 -p 3306 shutdown

7、查看初始化 root 密码并修改

more /mysql/data/mysql3306/log/mysqld3306.log|grep password 
more /mysql/data/mysql3306/log/mysqld3307.log|grep password 
more /mysql/data/mysql3306/log/mysqld3308.log|grep password

如下图所示,3306 端口 root@localhost密码为“gw*qxywss7;f”,初始化密码比较复杂,这里由于是测试环境,将其修改为“root”;

图片.png

[mysql@ops-11gogg ~]$ mysql -uroot -p  -p 3306 -s /mysql/data/mysql3306/socket/mysql3306.sock
enter password: 
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 8
server version: 8.0.28
米乐app官网下载 copyright (c) 2000, 2022, oracle and/or its affiliates.
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> alter user root@'localhost' identified by 'root';
query ok, 0 rows affected (0.01 sec)
mysql> create user root@'%' identified by 'root';
query ok, 0 rows affected (0.02 sec)
mysql> grant all  privileges on *.* to root@'%'  with grant option;
query ok, 0 rows affected (0.00 sec)

图片.png

其他两台也是如此,并创建远程 root 登录账号。

三、构建主从环境

1、主库 3306 创建复制账号 rep

create user rep@'%' identified by 'rep';
grant replication client,replication slave on *.* to rep@'%';

图片.png

我这里需要置空 gtid 信息。

reset master;
show master status;

图片.png

快速构建主从

登录3307

mysql -uroot -p  -p 3307 -s /mysql/data/mysql3307/socket/mysql3307.sock
enter password: 
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 10
server version: 8.0.28 mysql community server - gpl
米乐app官网下载 copyright (c) 2000, 2022, oracle and/or its affiliates.
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>

图片.png

change master to master_host='192.168.75.86',master_port=3306,master_user='rep',master_password='rep',master_auto_position=1;
show slave status\g
start slave;
show slave status\g
mysql> start slave;
query ok, 0 rows affected, 1 warning (1.04 sec)
mysql> show slave status\g
*************************** 1. row ***************************
               slave_io_state: waiting for source to send event
                  master_host: 192.168.75.86
                  master_user: rep
                  master_port: 3306
                connect_retry: 60
              master_log_file: mysql_bin.000002
          read_master_log_pos: 1486
               relay_log_file: relay.000002
                relay_log_pos: 373
        relay_master_log_file: mysql_bin.000002
             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: 1396
                   last_error: coordinator stopped because there were error(s) in the worker(s). the most recent failure being: worker 1 failed executing transaction '3ba436e0-aa7c-11ec-bba1-0050568a6bf6:2' at master log mysql_bin.000002, end_log_pos 730. see error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
                 skip_counter: 0
          exec_master_log_pos: 157
              relay_log_space: 1902
              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: 1396
               last_sql_error: coordinator stopped because there were error(s) in the worker(s). the most recent failure being: worker 1 failed executing transaction '3ba436e0-aa7c-11ec-bba1-0050568a6bf6:2' at master log mysql_bin.000002, end_log_pos 730. see error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
  replicate_ignore_server_ids: 
             master_server_id: 863306
                  master_uuid: 3ba436e0-aa7c-11ec-bba1-0050568a6bf6
             master_info_file: mysql.slave_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: 220323 16:03:06
               master_ssl_crl: 
           master_ssl_crlpath: 
           retrieved_gtid_set: 3ba436e0-aa7c-11ec-bba1-0050568a6bf6:1-5
            executed_gtid_set: 3ba436e0-aa7c-11ec-bba1-0050568a6bf6:1
                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, 1 warning (0.01 sec)

修复问题

show master status;
stop slave;
reset slave all;
reset master;

图片.png

登录3306

mysql -uroot -p  -p 3306 -s /mysql/data/mysql3306/socket/mysql3306.sock
show master status;
reset master;
show master status;

图片.png

重新构建主从

图片.png

注意:从 mysql 8.0.22 开始,start slave、stop slave、show slave status、show slave host、reset slave 均被弃用,取而代之的则是 start replica、stop replica、show replica status、show replicas 和 reset replica。 mysql 8.0.23 版本开始,change replication source to 取代了以前一直使用的 change master to 命令。mysql 8.0.26 版本开始,系统变量、参数等标识符中的 master、slave、mts(multithreaded slave)将被 source、replica 和 mta(multithreaded applier) 取代。

登录3307

[mysql@ops-11gogg conf]$ mysql -uroot -p  -p 3307 -s /mysql/data/mysql3307/socket/mysql3307.sock
enter password: 
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 29
server version: 8.0.28 mysql community server - gpl
米乐app官网下载 copyright (c) 2000, 2022, oracle and/or its affiliates.
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> change master to master_host='192.168.75.86',master_port=3306,master_user='rep',master_password='rep',master_auto_position=1;
query ok, 0 rows affected, 8 warnings (0.03 sec)
mysql> start slave;
query ok, 0 rows affected, 1 warning (0.05 sec)
mysql> show slave status\g
*************************** 1. row ***************************
               slave_io_state: waiting for source to send event
                  master_host: 192.168.75.86
                  master_user: rep
                  master_port: 3306
                connect_retry: 60
              master_log_file: mysql_bin.000001
          read_master_log_pos: 157
               relay_log_file: relay.000002
                relay_log_pos: 373
        relay_master_log_file: mysql_bin.000001
             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: 157
              relay_log_space: 573
              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: 863306
                  master_uuid: 3ba436e0-aa7c-11ec-bba1-0050568a6bf6
             master_info_file: mysql.slave_master_info
                    sql_delay: 0
          sql_remaining_delay: null
      slave_sql_running_state: replica 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, 1 warning (0.01 sec)

登录 3308

[mysql@ops-11gogg conf]$ mysql -uroot -p  -p 3308 -s /mysql/data/mysql3308/socket/mysql3308.sock
enter password: 
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 9
server version: 8.0.28 mysql community server - gpl
米乐app官网下载 copyright (c) 2000, 2022, oracle and/or its affiliates.
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> show master status;
 ------------------ ---------- -------------- ------------------ ------------------- 
| file             | position | binlog_do_db | binlog_ignore_db | executed_gtid_set |
 ------------------ ---------- -------------- ------------------ ------------------- 
| mysql_bin.000001 |      157 |              |                  |                   |
 ------------------ ---------- -------------- ------------------ ------------------- 
1 row in set (0.00 sec)
mysql> change master to master_host='192.168.75.86',master_port=3306,master_user='rep',master_password='rep',master_auto_position=1;
query ok, 0 rows affected, 8 warnings (0.03 sec)
mysql> start slave;
query ok, 0 rows affected, 1 warning (0.35 sec)
mysql> show slave status\g
*************************** 1. row ***************************
               slave_io_state: waiting for source to send event
                  master_host: 192.168.75.86
                  master_user: rep
                  master_port: 3306
                connect_retry: 60
              master_log_file: mysql_bin.000001
          read_master_log_pos: 157
               relay_log_file: relay.000002
                relay_log_pos: 373
        relay_master_log_file: mysql_bin.000001
             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: 157
              relay_log_space: 573
              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: 863306
                  master_uuid: 3ba436e0-aa7c-11ec-bba1-0050568a6bf6
             master_info_file: mysql.slave_master_info
                    sql_delay: 0
          sql_remaining_delay: null
      slave_sql_running_state: replica 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, 1 warning (0.01 sec)

登录主库 3306 查看

show slave hosts;

图片.png

[mysql@ops-11gogg conf]$ mysql -uroot -p  -p 3306 -s /mysql/data/mysql3306/socket/mysql3306.sock
enter password: 
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 13
server version: 8.0.28 mysql community server - gpl
米乐app官网下载 copyright (c) 2000, 2022, oracle and/or its affiliates.
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 slave hosts;
 ----------- ------------- ------ ----------- -------------------------------------- 
| server_id | host        | port | master_id | slave_uuid                           |
 ----------- ------------- ------ ----------- -------------------------------------- 
|    863308 | 192.168.75.86 | 3308 |    863306 | efeadd1c-aa7c-11ec-a0e3-0050568a6bf6 |
|    863307 | 192.168.75.86 | 3307 |    863306 | e0d081ae-aa7c-11ec-9b41-0050568a6bf6 |
 ----------- ------------- ------ ----------- -------------------------------------- 
2 rows in set, 1 warning (0.00 sec)
mysql> show processlist;
 ---- ----------------- ------------------- ------ ------------------ ------ ----------------------------------------------------------------- ------------------ 
| id | user            | host              | db   | command          | time | state                                                           | info             |
 ---- ----------------- ------------------- ------ ------------------ ------ ----------------------------------------------------------------- ------------------ 
|  5 | event_scheduler | localhost         | null | daemon           | 1467 | waiting on empty queue                                          | null             |
| 11 | rep             | 192.168.75.86:50360 | null | binlog dump gtid |  232 | source has sent all binlog to replica; waiting for more updates | null             |
| 12 | rep             | 192.168.75.86:50420 | null | binlog dump gtid |  109 | source has sent all binlog to replica; waiting for more updates | null             |
| 13 | root            | localhost         | null | query            |    0 | init                                                            | show processlist |
 ---- ----------------- ------------------- ------ ------------------ ------ ----------------------------------------------------------------- ------------------ 
4 rows in set (0.00 sec)

两从库分别修改参数限制只读模式

show variables like '%read_only%';
set global read_only=1;
set global super_read_only=1;

图片.png

[mysql@ops-11gogg conf]$ mysql -uroot -p  -p 3308 -s /mysql/data/mysql3308/socket/mysql3308.sock
enter password: 
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 28
server version: 8.0.28 mysql community server - gpl
米乐app官网下载 copyright (c) 2000, 2022, oracle and/or its affiliates.
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 master status;
 ------------------ ---------- -------------- ------------------ ------------------------------------------ 
| file             | position | binlog_do_db | binlog_ignore_db | executed_gtid_set                        |
 ------------------ ---------- -------------- ------------------ ------------------------------------------ 
| mysql_bin.000001 |      544 |              |                  | 3ba436e0-aa7c-11ec-bba1-0050568a6bf6:1-2 |
 ------------------ ---------- -------------- ------------------ ------------------------------------------ 
1 row in set (0.00 sec)
mysql> show variables like '%read_only%';
 ----------------------- ------- 
| variable_name         | value |
 ----------------------- ------- 
| innodb_read_only      | off   |
| read_only             | off   |
| super_read_only       | off   |
| transaction_read_only | off   |
 ----------------------- ------- 
4 rows in set (0.02 sec)
mysql> set global read_only=1;
query ok, 0 rows affected (0.00 sec)
mysql> set global super_read_only=1;
query ok, 0 rows affected (0.00 sec)
mysql> show variables like '%read_only%';
 ----------------------- ------- 
| variable_name         | value |
 ----------------------- ------- 
| innodb_read_only      | off   |
| read_only             | on    |
| super_read_only       | on    |
| transaction_read_only | off   |
 ----------------------- ------- 
4 rows in set (0.01 sec)
mysql> show master status;
 ------------------ ---------- -------------- ------------------ ------------------------------------------ 
| file             | position | binlog_do_db | binlog_ignore_db | executed_gtid_set                        |
 ------------------ ---------- -------------- ------------------ ------------------------------------------ 
| mysql_bin.000001 |      544 |              |                  | 3ba436e0-aa7c-11ec-bba1-0050568a6bf6:1-2 |
 ------------------ ---------- -------------- ------------------ ------------------------------------------ 
1 row in set (0.00 sec)

————————————————————————————
公众号:jiekexu dba之路
墨天轮:https://www.modb.pro/u/4347
csdn :https://blog.csdn.net/jiekexu
腾讯云:https://cloud.tencent.com/developer/user/5645107
————————————————————————————
图片.png

最后修改时间:2023-05-17 11:24:38
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
1人已赞赏
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

网站地图