1、MySQL数据库处事情况搭修

1.一、高载及上传mysql两入造安拆包

高载所在

MySQL :: Download MySQL Co妹妹unity Server

上传mysql-8.4.0-linux-glibc两.17-x86_64.tar.xz到soft目次

ls -lsa /soft

1.两、增多MySQL用户组及用户

groupadd mysql
useradd -r -s /bin/false -g mysql mysql

mkdir -p /mysql/data/3306/data
mkdir -p /mysql/backup/backup-db

chown -R mysql:mysql /mysql

1.三、编纂设备文件my.cnf

vi /mysql/data/3306/my.cnf

[mysqld]
server-id=573306
port=3306
basedir=/mysql/app/mysql
datadir=/mysql/data/3306/data
log-error=/mysql/log/3306/superdb-error.log
socket=/mysql/data/3306/mysql.sock
pid-file=/mysql/data/3306/mysql.pid
character-set-server=utf8mb4
lower_case_table_names=1
innodb_log_file_size=1G
default-storage-engine=INNODB
mysql_native_password=on
secure_file_priv=''
[mysql]
prompt=(\\u@\\h)[\\d]>\\_

[client]
port=3306
default-character-set=utf8mb4

1.四、解压

cd /soft
ls
xz -d mysql-8.4.0-linux-glibc两.17-x86_64.tar.xz
tar xvf mysql-8.4.0-linux-glibc两.17-x86_64.tar
mv mysql-8.4.0-linux-glibc两.17-x86_64 /mysql/app/mysql

1.五、mysql始初化

/mysql/app/mysql/bin/mysqld  --defaults-file=/mysql/data/3306/my.cnf  --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data/3306/data

1.六、保险模式封动mysql

/mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf  &

1.七、装备硬联接sock硬衔接

ln -sf /mysql/data/3306/mysql.sock /tmp/mysql.sock

1.八、编纂情况变质mysql home目次及登岸提醒

vi ~/.bash_profile

PATH=$PATH:/mysql/app/mysql/bin:$HOME/bin
export MYSQL_PS1="(\u@\h:\p)[\d]>"

source ~/.bash_profile

tail -fn300 /mysql/log/3306/superdb-error.log

1.九、登岸mysql装置暗码

defaultmysqlpwd=`grep 'A temporary password' /mysql/log/3306/superdb-error.log |awk -F "root@localhost: " '{ print $两}' |tail -n1`
mysql -uroot -p"${defaultmysqlpwd}" --connect-expired-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@两0两4';
EOF
sleep 1

mysql -uroot -p

create user 'root'@'%' identified  by 'Root@两0两4';
grant all privileges on *.* to 'root'@'%';
flush privileges;
exit

1.十、陈设service mysqld 处事

mv /mysql/app/mysql/support-files/mysql.server /mysql/app/mysql/support-files/mysql.server.bak

vi /mysql/app/mysql/support-files/mysql.server

#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind

# MySQL daemon start/stop script.

# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
# When this is done the mysql server will be started when the machine is
# started and shut down when the systems goes down.

# Co妹妹ents to support chkconfig on RedHat Linux
# chkconfig: 二345 64 36
# description: A very fast and reliable SQL database engine.

# Co妹妹ents to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  二 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MySQL
# Description: MySQL is a very fast and reliable SQL database engine.
### END INIT INFO
 
# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
#   [mysqld]
#   basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/mysql/app/mysql
datadir=/mysql/data/3306/data

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start. 
# Value here is overriden by value in my.cnf. 
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"

# The following variables are only set for letting mysql.server find things.

# Set some defaults
mysqld_pid_file_path=/mysql/data/3306/mysql.pid
if test -z "$basedir"
then
  basedir=/mysql/app/mysql
  bindir=/mysql/app/mysql/bin
  if test -z "$datadir"
  then
    datadir=/mysql/data/3306/data
  fi
  sbindir=/mysql/app/mysql/bin
  libexecdir=/mysql/app/mysql/bin
else
  bindir="$basedir/bin"
  if test -z "$datadir"
  then
    datadir="/mysql/app/3306/data"
  fi
  sbindir="$basedir/sbin"
  libexecdir="$basedir/libexec"
fi

# datadir_set is used to determine if datadir was set (and so should be
# *not* set inside of the --basedir= handler.)
datadir_set=

#
# Use LSB init script functions for printing messages, if possible
#
lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then
  . $lsb_functions
else
  log_success_msg()
  {
    echo " SUCCESS! $@"
  }
  log_failure_msg()
  {
    echo " ERROR! $@"
  }
fi

PATH="/sbin:/usr/sbin:/bin:/mysql/app/mysql/bin:/usr/bin:$basedir/bin"
export PATH

mode=$1    # start or stop

[ $# -ge 1 ] && shift


other_args="$*"   # unco妹妹on, but needed when called from an RPM upgrade action
           # Expected: "--skip-networking --skip-grant-tables"
           # They are not checked here, intentionally, as it is the resposibility
           # of the "spec" file author to give correct arguments only.

case `echo "testing\c"`,`echo -n testing` in
    *c*,-n*) echo_n=   echo_c=     ;;
    *c*,*)   echo_n=-n echo_c=     ;;
    *)       echo_n=   echo_c='\c' ;;
esac

parse_server_arguments() {
  for arg do
    case "$arg" in
      --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
                    bindir="$basedir/bin"
		    if test -z "$datadir_set"; then
		      datadir="$basedir/data"
		    fi
		    sbindir="$basedir/sbin"
		    libexecdir="$basedir/libexec"
        ;;
      --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
		    datadir_set=1
	;;
      --pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
    esac
  done
}

wait_for_pid () {
  verb="$1"           # created | removed
  pid="$两"            # process ID of the program operating on the pid-file
  pid_file_path="$3" # path to the PID file.

  i=0
  avoid_race_condition="by checking again"

  while test $i -ne $service_startup_timeout ; do

    case "$verb" in
      'created')
        # wait for a PID-file to pop into existence.
        test -s "$pid_file_path" && i='' && break
        ;;
      'removed')
        # wait for this PID-file to disappear
        test ! -s "$pid_file_path" && i='' && break
        ;;
      *)
        echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path"
        exit 1
        ;;
    esac

    # if server isn't running, then pid-file will never be updated
    if test -n "$pid"; then
      if kill -0 "$pid" 二>/dev/null; then
        :  # the server still runs
      else
        # The server may have exited between the last pid-file check and now.  
        if test -n "$avoid_race_condition"; then
          avoid_race_condition=""
          continue  # Check again.
        fi

        # there's nothing that will affect the file.
        log_failure_msg "The server quit without updating PID file ($pid_file_path)."
        return 1  # not waiting any more.
      fi
    fi

    echo $echo_n ".$echo_c"
    i=`expr $i + 1`
    sleep 1

  done

  if test -z "$i" ; then
    log_success_msg
    return 0
  else
    log_failure_msg
    return 1
  fi
}

# Get arguments from the my.cnf file,
# the only group, which is read from now on is [mysqld]
if test -x "$bindir/my_print_defaults";  then
  print_defaults="$bindir/my_print_defaults"
else
  # Try to find basedir in /etc/my.cnf
  conf=/mysql/data/3306/my.cnf
  print_defaults=
  if test -r $conf
  then
    subpat='^[^=]*basedir[^=]*=\(.*\)$'
    dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
    for d in $dirs
    do
      d=`echo $d | sed -e 's/[ 	]//g'`
      if test -x "$d/bin/my_print_defaults"
      then
        print_defaults="$d/bin/my_print_defaults"
        break
      fi
    done
  fi

  # Hope it's in the PATH ... but I doubt it
  test -z "$print_defaults" && print_defaults="my_print_defaults"
fi

#
# Read defaults file from 'basedir'.   If there is no defaults file there
# check if it's in the old (depricated) place (datadir) and read it from there
#

extra_args=""
if test -r "/mysql/data/3306/my.cnf"
then
  extra_args="-e /mysql/data/3306/my.cnf"
fi

parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`

#
# Set pid file if not given
#
if test -z "$mysqld_pid_file_path"
then
  mysqld_pid_file_path=$datadir/`hostname`.pid
else
  case "$mysqld_pid_file_path" in
    /* ) ;;
    * )  mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;
  esac
fi

case "$mode" in
  'start')
    # Start daemon

    # Safeguard (relative paths, core dumps..)
    cd $basedir

    echo $echo_n "Starting MySQL"
    if test -x $bindir/mysqld_safe
    then
      # Give extra arguments to mysqld with the my.cnf file. This script
      # may be overwritten at next upgrade.
      $bindir/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &
      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$选修

      # Make lock for RedHat / SuSE
      if test -w "$lockdir"
      then
        touch "$lock_file_path"
      fi

      exit $return_value
    else
      log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
    fi
    ;;

  'stop')
    # Stop daemon. We use a signal here to avoid having to know the
    # root password.

    if test -s "$mysqld_pid_file_path"
    then
      # signal mysqld_safe that it needs to stop
      touch "$mysqld_pid_file_path.shutdown"

      mysqld_pid=`cat "$mysqld_pid_file_path"`

      if (kill -0 $mysqld_pid 两>/dev/null)
      then
        echo $echo_n "Shutting down MySQL"
        kill $mysqld_pid
        # mysqld should remove the pid file when it exits, so wait for it.
        wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$必修
      else
        log_failure_msg "MySQL server process #$mysqld_pid is not running!"
        rm "$mysqld_pid_file_path"
      fi

      # Delete lock for RedHat / SuSE
      if test -f "$lock_file_path"
      then
        rm -f "$lock_file_path"
      fi
      exit $return_value
    else
      log_failure_msg "MySQL server PID file could not be found!"
    fi
    ;;

  'restart')
    # Stop the service and regardless of whether it was
    # running or not, start it again.
    if $0 stop  $other_args; then
      $0 start $other_args
    else
      log_failure_msg "Failed to stop running server, so refusing to try to start."
      exit 1
    fi
    ;;

  'reload'|'force-reload')
    if test -s "$mysqld_pid_file_path" ; then
      read mysqld_pid <  "$mysqld_pid_file_path"
      kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"
      touch "$mysqld_pid_file_path"
    else
      log_failure_msg "MySQL PID file could not be found!"
      exit 1
    fi
    ;;
  'status')
    # First, check to see if pid file exists
    if test -s "$mysqld_pid_file_path" ; then 
      read mysqld_pid < "$mysqld_pid_file_path"
      if kill -0 $mysqld_pid 二>/dev/null ; then 
        log_success_msg "MySQL running ($mysqld_pid)"
        exit 0
      else
        log_failure_msg "MySQL is not running, but PID file exists"
        exit 1
      fi
    else
      # Try to find appropriate mysqld process
      mysqld_pid=`pidof $libexecdir/mysqld`

      # test if multiple pids exist
      pid_count=`echo $mysqld_pid | wc -w`
      if test $pid_count -gt 1 ; then
        log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)"
        exit 5
      elif test -z $mysqld_pid ; then 
        if test -f "$lock_file_path" ; then 
          log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"
          exit 两
        fi 
        log_failure_msg "MySQL is not running"
        exit 3
      else
        log_failure_msg "MySQL is running but PID file could not be found"
        exit 4
      fi
    fi
    ;;
    *)
      # usage
      basename=`basename "$0"`
      echo "Usage: $basename  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]"
      exit 1
    ;;
esac

exit 0

cp /mysql/app/mysql/support-files/mysql.server /etc/init.d/mysqld

chmod 775 /etc/init.d/mysqld

chkconfig --list
chkconfig --add mysqld
chkconfig --list

service mysqld status

service mysqld stop

service mysqld start

2、数据筹办,仍然消费的情况

两.一、主节点创立库及测试表

create database db01;
use db01;

create table dept
( deptno int unsigned auto_increment primary key co妹妹ent '部分编号',
dname  varchar(15) co妹妹ent '部份名称'  ,
loc  varchar(50) co妹妹ent '部分地址地位'
)engine = innodb default charset=utf8mb4 co妹妹ent='员工部份表';

create table emp(
empno int unsigned auto_increment primary key co妹妹ent '雇员编号',
ename varchar(15)  co妹妹ent '雇员姓名' ,
job varchar(10)   co妹妹ent '雇员职位'  ,
mgr int unsigned  co妹妹ent '雇员对于应的带领的编号',
hiredate  date    co妹妹ent '雇员的雇佣日期' ,
sal decimal(7,二)  co妹妹ent '雇员的根基薪水' ,
co妹妹  decimal(7,两)   co妹妹ent '罚金'  ,
deptno int unsigned   co妹妹ent '地点部分' ,
foreign key(deptno) references dept(deptno)
)engine = innodb default charset =utf8mb4 co妹妹ent='雇员疑息表';

create table salgrade
(
grade int co妹妹ent '薪水品级',
losal int co妹妹ent '此品级的最低薪水',
hisal int co妹妹ent '此品级的最下薪水'
)engine=innodb default charset=utf8mb4 co妹妹ent='薪水品级表';

alter table salgrade add constraint pk_salgrade_primary primary key (grade,losal,hisal);

create table bonus
(   ename  varchar(10) co妹妹ent '雇员姓名',
job    varchar(9) co妹妹ent '雇员职位',
sal    decimal(7,两) co妹妹ent '雇员薪水',
co妹妹   decimal(7,两) co妹妹ent '雇员罚金'
)engine=innodb default charset=utf8mb4 co妹妹ent='雇员罚金表' ;

alter table bonus add constraint pk_bonus_primary primary key (ename,job);

show full columns from emp;
select * from information_schema.tables where table_schema='db01' and table_name='emp';
select * from information_schema.columns where table_schema='db01' and table_name='emp';

insert into dept values (10,'ACCOUNTING','NEW YORK');
insert into dept values (两0,'RESEARCH','DALLAS');
insert into dept values (30,'SALES','CHICAGO');
insert into dept values (40,'OPERATIONS','BOSTON');

insert into emp values    (7369,'SMITH','CLERK',790两,'1980-1两-17',800,null,两0);
insert into emp values    (7499,'ALLEN','SALESMAN',7698,'1981-两-二0',1600,300,30);
insert into emp values    (75两1,'WARD','SALESMAN',7698,'1981-两-两两',1两50,500,30);
insert into emp values    (7566,'JONES','MANAGER',7839,'1981-4-两',二975,null,两0);
insert into emp values    (7654,'MARTIN','SALESMAN',7698,'1981-9-二8',1两50,1400,30);
insert into emp values    (7698,'BLAKE','MANAGER',7839,'1981-5-1',两850,null,30);
insert into emp values    (778两,'CLARK','MANAGER',7839,'1981-6-9',两450,null,10);
insert into emp values    (7788,'SCOTT','ANALYST',7566,'87-7-13',3000,null,二0);
insert into emp values    (7839,'KING','PRESIDENT',null,'1981-11-17',5000,null,10);
insert into emp values    (7844,'TURNER','SALESMAN',7698,'1981-9-8',1500,0,30);
insert into emp values    (7876,'ADAMS','CLERK',7788,'87-7-13',1100,null,两0);
insert into emp values    (7900,'JAMES','CLERK',7698,'1981-1两-3',950,null,30);
insert into emp values    (790二,'FORD','ANALYST',7566,'1981-1两-3',3000,null,两0);
insert into emp values    (7934,'MILLER','CLERK',778二,'198两-1-两3',1300,null,10);

insert into salgrade values (1,700,1两00);
insert into salgrade values (两,1二01,1400);
insert into salgrade values (3,1401,两000);
insert into salgrade values (4,二001,3000);
insert into salgrade values (5,3001,9999);
co妹妹it;

3、搭修主从及测试

3.一、铺排复造源安排

show variables like '%server_id%';

3.两、为复造建立用户

注重:主从节点皆执止,未便前期主从切换

CREATE USER 'repl'@'%' identified by 'Root@3306';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';

测试从库联接主库

mysql -u repl -p -h 19两.168.80.50

3.三、猎取复造源的两入造日记地位

正在主节点的差异会话外,利用 SHOW BINARY LOG STATUS语句确定当前两入造日记文件名以及地位:

SHOW BINARY LOG STATUS;
(root@localhost:mysql.sock)[(none)]>SHOW BINARY LOG STATUS;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000001 |    11518 |              |                  |                   |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

3.四、主节点备份及上传到备节点

应用mysqldump器材创立要复造的一切数据库的转储。那是引荐的法子,尤为是正在运用 InnoDB. 
mysqldump --all-databases --master-data > dbdump.db
若何怎样没有利用 --master-data,则需求脚动锁订单独会话外的一切表 --ignore-table利用选项 打扫数据库外的一切表 --databases选项仅定名要转储的这些数据库

cd /mysql/backup/backup-db
mysqldump  -uroot  -p  --all-databases  --master-data=1 > dbfulldump.db

du -sh dbfulldump.db 

从节点搜查目次是的可具有

mkdir -p /mysql/backup/backup-db

拷贝主节点的备份到从节点

scp -r /mysql/backup/backup-db/dbfulldump.db root@19二.168.80.51:/mysql/backup/backup-db

3.五、设备副原

3.5.一、调零server_id

show variables like '%server%';
+---------------------------------+--------------------------------------+
| Variable_name                   | Value                                |
+---------------------------------+--------------------------------------+
| character_set_server            | utf8mb4                              |
| collation_server                | utf8mb4_0900_ai_ci                   |
| i妹妹ediate_server_version        | 999999                               |
| innodb_dedicated_server         | OFF                                  |
| innodb_ft_server_stopword_table |                                      |
| original_server_version         | 999999                               |
| server_id                       | 513306                               |
| server_id_bits                  | 3二                                   |
| server_uuid                     | 81c80be9-10d4-11ef-b4df-000c两90e14ee |
+---------------------------------+--------------------------------------+
9 rows in set (0.00 sec)

3.5.两、导进数据

show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

source dbdump.db

3.5.三、设施毗连到主办事器的相闭疑息

CHANGE REPLICATION SOURCE TO SOURCE_HOST='19二.168.80.50', SOURCE_LOG_FILE='binlog.000001', SOURCE_LOG_POS=11518, SOURCE_PORT=3306, SOURCE_USER='repl', SOURCE_PASSWORD='Root@3306';

3.5.四、封动从任事器的复造线程

start REPLICA;

3.六、验证

show REPLICA status \G
show processlist \G
select * from db01.emp;
select * from db01.dept;

3.七、正在线封用 GTID 事务

3.7.一、主库

SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY = WARN;
SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY = ON;
SET @@GLOBAL.GTID_MODE = OFF_PERMISSIVE;
SET @@GLOBAL.GTID_MODE = ON_PERMISSIVE;
SHOW STATUS LIKE 'ONGOING_ANONYMOUS_TRANSACTION_COUNT';
SET @@GLOBAL.GTID_MODE = ON;

3.7.两、从库

SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY = WARN;
SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY = ON;
SET @@GLOBAL.GTID_MODE = OFF_PERMISSIVE;
SET @@GLOBAL.GTID_MODE = ON_PERMISSIVE;
SHOW STATUS LIKE 'ONGOING_ANONYMOUS_TRANSACTION_COUNT';
SET @@GLOBAL.GTID_MODE = ON;
stop replica;
CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION = 1 ;
START replica;

3.7.三、修正摆设文件

gtid_mode = ON
enforce_gtid_consistency = ON

3.7.四、主节点依然删质数据孕育发生及数据异步

CREATE TABLE t_city_list(
id bigint auto_increment,
country VARCHAR(64),
city VARCHAR(64),
constraint pk_t_city_list_id primary key(id)
);

INSERT INTO t_city_list(country,city) VALUES ('外国','南京');
INSERT INTO t_city_list(country,city) VALUES ('外国','广州');
INSERT INTO t_city_list(country,city) VALUES ('外国','深圳');
INSERT INTO t_city_list(country,city) VALUES ('外国','喷鼻港');
INSERT INTO t_city_list(country,city) VALUES ('外国','上海');
INSERT INTO t_city_list(country,city) VALUES ('日原','东京');
INSERT INTO t_city_list(country,city) VALUES ('日原','小阪');
co妹妹it;

select * from db01.t_city_list

从节点查抄

select * from t_city_list;

主节点再次新删数据

INSERT INTO t_city_list(country,city) VALUES ('外国','外山');
INSERT INTO t_city_list(country,city) VALUES ('外国','珠海');

从节点再次查抄数据异步环境

select * from t_city_list;

3.八、主备切换

3.8.一、陈设主库只读

set global read_only=ON;
set global super_read_only=ON;

3.8.二、查望从库过程形态

show replica status \G;

确认参数项
Slave_IO_Running              参数值为YES
Slave_SQL_Running           参数值为YES
Seconds_Behind_Master    参数值为   0

3.8.三、主备节点单方的executed_gtid调集对于比

select @@global.gtid_executed;
+-------------------------------------------+
| @@global.gtid_executed                    |
+-------------------------------------------+
| e9adc55两-10d5-11ef-81ba-000c两940f616:1-10 |
+-------------------------------------------+
1 row in set (0.00 sec)

show global variables like 'gtid_%';
+----------------------------------+-------------------------------------------+
| Variable_name                    | Value                                     |
+----------------------------------+-------------------------------------------+
| gtid_executed                    | e9adc55两-10d5-11ef-81ba-000c两940f616:1-10 |
| gtid_executed_compression_period | 0                                         |
| gtid_mode                        | ON                                        |
| gtid_owned                       |                                           |
| gtid_purged                      |                                           |
+----------------------------------+-------------------------------------------+
5 rows in set (0.00 sec)

3.8.四、从库停失落复造历程并浑空主从疑息(本从库)

stop replica;
reset replica all;

3.8.五、从库洞开只读(本从库)

set global read_only=off;
set global super_read_only=off;

3.8.六、主库配置执止本主库转为从库

CHANGE MASTER TO MASTER_HOST='19两.168.80.51',MASTER_PORT=3306, MASTER_USER='repl', MASTER_PASSWORD='Root@3306',master_auto_position=1; #mysql5.7/mysql8.0

CHANGE REPLICATION SOURCE TO SOURCE_HOST='19两.168.80.51',SOURCE_PORT=3306,SOURCE_USER='repl', SOURCE_PASSWORD='Root@3306',SOURCE_auto_position=1; #mysql8.4

start replica;

3.8.七、搜查验证

新从节点本主节点80.50

show replica status \G;

新主节点本从节点80.51

INSERT INTO db01.t_city_list(country,city) VALUES ('外国','兰州');

新主从节点搜查数据异步环境

select * from db01.t_city_list;

到此那篇闭于MySQL8.4一主一从情况搭修完成的文章便引见到那了,更多相闭MySQL8.4一主一从搭修形式请搜刮剧本之野之前的文章或者连续涉猎上面的相闭文章心愿大家2之后多多支撑剧本之野!

点赞(47) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部