MySQL8.4一主一從環(huán)境搭建實(shí)現(xiàn)
一、MySQL數(shù)據(jù)庫服務(wù)環(huán)境搭建
1.1、下載及上傳mysql二進(jìn)制安裝包
下載地址
MySQL :: Download MySQL Community Server
上傳mysql-8.4.0-linux-glibc2.17-x86_64.tar.xz到soft目錄
ls -lsa /soft
1.2、增加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.3、編輯配置文件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.4、解壓
cd /soft ls xz -d mysql-8.4.0-linux-glibc2.17-x86_64.tar.xz tar xvf mysql-8.4.0-linux-glibc2.17-x86_64.tar mv mysql-8.4.0-linux-glibc2.17-x86_64 /mysql/app/mysql
1.5、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.6、安全模式啟動(dòng)mysql
/mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf &
1.7、設(shè)置軟連接sock軟連接
ln -sf /mysql/data/3306/mysql.sock /tmp/mysql.sock
1.8、編輯環(huán)境變量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.9、登陸mysql設(shè)置密碼
defaultmysqlpwd=`grep 'A temporary password' /mysql/log/3306/superdb-error.log |awk -F "root@localhost: " '{ print $2}' |tail -n1` mysql -uroot -p"${defaultmysqlpwd}" --connect-expired-password <<EOF ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@2024'; EOF sleep 1 mysql -uroot -p create user 'root'@'%' identified by 'Root@2024'; grant all privileges on *.* to 'root'@'%'; flush privileges; exit
1.10、設(shè)置service mysqld 服務(wù)
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. # Comments to support chkconfig on RedHat Linux # chkconfig: 2345 64 36 # description: A very fast and reliable SQL database engine. # Comments 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: 2 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="$*" # uncommon, 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="$2" # 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" 2>/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 2>/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 2>/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 2 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
二、數(shù)據(jù)準(zhǔn)備,模擬生產(chǎn)的環(huán)境
2.1、主節(jié)點(diǎn)創(chuàng)建庫及測試表
create database db01; use db01; create table dept ( deptno int unsigned auto_increment primary key comment '部門編號(hào)', dname varchar(15) comment '部門名稱' , loc varchar(50) comment '部門所在位置' )engine = innodb default charset=utf8mb4 comment='員工部門表'; create table emp( empno int unsigned auto_increment primary key comment '雇員編號(hào)', ename varchar(15) comment '雇員姓名' , job varchar(10) comment '雇員職位' , mgr int unsigned comment '雇員對應(yīng)的領(lǐng)導(dǎo)的編號(hào)', hiredate date comment '雇員的雇傭日期' , sal decimal(7,2) comment '雇員的基本工資' , comm decimal(7,2) comment '獎(jiǎng)金' , deptno int unsigned comment '所在部門' , foreign key(deptno) references dept(deptno) )engine = innodb default charset =utf8mb4 comment='雇員信息表'; create table salgrade ( grade int comment '工資等級(jí)', losal int comment '此等級(jí)的最低工資', hisal int comment '此等級(jí)的最高工資' )engine=innodb default charset=utf8mb4 comment='工資等級(jí)表'; alter table salgrade add constraint pk_salgrade_primary primary key (grade,losal,hisal); create table bonus ( ename varchar(10) comment '雇員姓名', job varchar(9) comment '雇員職位', sal decimal(7,2) comment '雇員工資', comm decimal(7,2) comment '雇員獎(jiǎng)金' )engine=innodb default charset=utf8mb4 comment='雇員獎(jiǎng)金表' ; 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 (20,'RESEARCH','DALLAS'); insert into dept values (30,'SALES','CHICAGO'); insert into dept values (40,'OPERATIONS','BOSTON'); insert into emp values (7369,'SMITH','CLERK',7902,'1980-12-17',800,null,20); insert into emp values (7499,'ALLEN','SALESMAN',7698,'1981-2-20',1600,300,30); insert into emp values (7521,'WARD','SALESMAN',7698,'1981-2-22',1250,500,30); insert into emp values (7566,'JONES','MANAGER',7839,'1981-4-2',2975,null,20); insert into emp values (7654,'MARTIN','SALESMAN',7698,'1981-9-28',1250,1400,30); insert into emp values (7698,'BLAKE','MANAGER',7839,'1981-5-1',2850,null,30); insert into emp values (7782,'CLARK','MANAGER',7839,'1981-6-9',2450,null,10); insert into emp values (7788,'SCOTT','ANALYST',7566,'87-7-13',3000,null,20); 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,20); insert into emp values (7900,'JAMES','CLERK',7698,'1981-12-3',950,null,30); insert into emp values (7902,'FORD','ANALYST',7566,'1981-12-3',3000,null,20); insert into emp values (7934,'MILLER','CLERK',7782,'1982-1-23',1300,null,10); insert into salgrade values (1,700,1200); insert into salgrade values (2,1201,1400); insert into salgrade values (3,1401,2000); insert into salgrade values (4,2001,3000); insert into salgrade values (5,3001,9999); commit;
三、搭建主從及測試
3.1、設(shè)置復(fù)制源配置
show variables like '%server_id%';
3.2、為復(fù)制創(chuàng)建用戶
注意:主從節(jié)點(diǎn)都執(zhí)行,方便后期主從切換
CREATE USER 'repl'@'%' identified by 'Root@3306'; GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
測試從庫連接主庫
mysql -u repl -p -h 192.168.80.50
3.3、獲取復(fù)制源的二進(jìn)制日志位置
在主節(jié)點(diǎn)的不同會(huì)話中,使用 SHOW BINARY LOG STATUS語句確定當(dāng)前二進(jìn)制日志文件名和位置:
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.4、主節(jié)點(diǎn)備份及上傳到備節(jié)點(diǎn)
使用mysqldump工具創(chuàng)建要復(fù)制的所有數(shù)據(jù)庫的轉(zhuǎn)儲(chǔ)。這是推薦的方法,尤其是在使用 InnoDB.
mysqldump --all-databases --master-data > dbdump.db
如果不使用 --master-data,則需要手動(dòng)鎖定單獨(dú)會(huì)話中的所有表 --ignore-table使用選項(xiàng) 排除數(shù)據(jù)庫中的所有表 --databases選項(xiàng)僅命名要轉(zhuǎn)儲(chǔ)的那些數(shù)據(jù)庫
cd /mysql/backup/backup-db mysqldump -uroot -p --all-databases --master-data=1 > dbfulldump.db
du -sh dbfulldump.db
從節(jié)點(diǎn)檢查目錄是的否存在
mkdir -p /mysql/backup/backup-db
拷貝主節(jié)點(diǎn)的備份到從節(jié)點(diǎn)
scp -r /mysql/backup/backup-db/dbfulldump.db root@192.168.80.51:/mysql/backup/backup-db
3.5、設(shè)置副本
3.5.1、調(diào)整server_id
show variables like '%server%'; +---------------------------------+--------------------------------------+ | Variable_name | Value | +---------------------------------+--------------------------------------+ | character_set_server | utf8mb4 | | collation_server | utf8mb4_0900_ai_ci | | immediate_server_version | 999999 | | innodb_dedicated_server | OFF | | innodb_ft_server_stopword_table | | | original_server_version | 999999 | | server_id | 513306 | | server_id_bits | 32 | | server_uuid | 81c80be9-10d4-11ef-b4df-000c290e14ee | +---------------------------------+--------------------------------------+ 9 rows in set (0.00 sec)
3.5.2、導(dǎo)入數(shù)據(jù)
show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
source dbdump.db
3.5.3、配置連接到主服務(wù)器的相關(guān)信息
CHANGE REPLICATION SOURCE TO SOURCE_HOST='192.168.80.50', SOURCE_LOG_FILE='binlog.000001', SOURCE_LOG_POS=11518, SOURCE_PORT=3306, SOURCE_USER='repl', SOURCE_PASSWORD='Root@3306';
3.5.4、啟動(dòng)從服務(wù)器的復(fù)制線程
start REPLICA;
3.6、驗(yàn)證
show REPLICA status \G show processlist \G select * from db01.emp; select * from db01.dept;
3.7、在線啟用 GTID 事務(wù)
3.7.1、主庫
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.2、從庫
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.3、修改配置文件
gtid_mode = ON enforce_gtid_consistency = ON
3.7.4、主節(jié)點(diǎn)模擬增量數(shù)據(jù)產(chǎn)生及數(shù)據(jù)同步
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 ('日本','大阪'); commit; select * from db01.t_city_list
從節(jié)點(diǎn)檢查
select * from t_city_list;
主節(jié)點(diǎn)再次新增數(shù)據(jù)
INSERT INTO t_city_list(country,city) VALUES ('中國','中山'); INSERT INTO t_city_list(country,city) VALUES ('中國','珠海');
從節(jié)點(diǎn)再次檢查數(shù)據(jù)同步情況
select * from t_city_list;
3.8、主備切換
3.8.1、設(shè)置主庫只讀
set global read_only=ON; set global super_read_only=ON;
3.8.2、查看從庫進(jìn)程狀態(tài)
show replica status \G;
確認(rèn)參數(shù)項(xiàng)
Slave_IO_Running 參數(shù)值為YES
Slave_SQL_Running 參數(shù)值為YES
Seconds_Behind_Master 參數(shù)值為 0
3.8.3、主備節(jié)點(diǎn)兩邊的executed_gtid集合對比
select @@global.gtid_executed; +-------------------------------------------+ | @@global.gtid_executed | +-------------------------------------------+ | e9adc552-10d5-11ef-81ba-000c2940f616:1-10 | +-------------------------------------------+ 1 row in set (0.00 sec) show global variables like 'gtid_%'; +----------------------------------+-------------------------------------------+ | Variable_name | Value | +----------------------------------+-------------------------------------------+ | gtid_executed | e9adc552-10d5-11ef-81ba-000c2940f616:1-10 | | gtid_executed_compression_period | 0 | | gtid_mode | ON | | gtid_owned | | | gtid_purged | | +----------------------------------+-------------------------------------------+ 5 rows in set (0.00 sec)
3.8.4、從庫停掉復(fù)制進(jìn)程并清空主從信息(原從庫)
stop replica; reset replica all;
3.8.5、從庫關(guān)閉只讀(原從庫)
set global read_only=off; set global super_read_only=off;
3.8.6、主庫設(shè)置執(zhí)行原主庫轉(zhuǎn)為從庫
CHANGE MASTER TO MASTER_HOST='192.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='192.168.80.51',SOURCE_PORT=3306,SOURCE_USER='repl', SOURCE_PASSWORD='Root@3306',SOURCE_auto_position=1; #mysql8.4 start replica;
3.8.7、檢查驗(yàn)證
新從節(jié)點(diǎn)原主節(jié)點(diǎn)80.50
show replica status \G;
新主節(jié)點(diǎn)原從節(jié)點(diǎn)80.51
INSERT INTO db01.t_city_list(country,city) VALUES ('中國','蘭州');
新主從節(jié)點(diǎn)檢查數(shù)據(jù)同步情況
select * from db01.t_city_list;
到此這篇關(guān)于MySQL8.4一主一從環(huán)境搭建實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)MySQL8.4一主一從搭建內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決Mysql建表時(shí)報(bào)錯(cuò)invalid?ON?UPDATE?clause?for?'create_d
這篇文章主要介紹了解決Mysql建表時(shí)報(bào)錯(cuò)invalid?ON?UPDATE?clause?for?'create_date'?column問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12MySQL按年/月/周/日/小時(shí)分組查詢、排序、limit及判空用法實(shí)例
我們在用Mysql抽取數(shù)據(jù)時(shí)候,經(jīng)常需要按照天、周、月等不同的粒度對數(shù)據(jù)進(jìn)行分組統(tǒng)計(jì),下面這篇文章主要給大家介紹了關(guān)于MySQL按年/月/周/日/小時(shí)分組查詢、排序、limit及判空用法的相關(guān)資料,需要的朋友可以參考下2023-03-03深入探討:MySQL數(shù)據(jù)庫MyISAM與InnoDB存儲(chǔ)引擎的比較
本篇文章是對MySQL數(shù)據(jù)庫MyISAM與InnoDB存儲(chǔ)引擎的比較進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06MySQL中導(dǎo)出用戶權(quán)限設(shè)置的腳本分享
這篇文章主要介紹了MySQL中導(dǎo)出用戶權(quán)限設(shè)置的腳本分享,本文通過導(dǎo)出mysql.user表中數(shù)據(jù)實(shí)現(xiàn)導(dǎo)出權(quán)限設(shè)置,需要的朋友可以參考下2014-10-10mysql中異常錯(cuò)誤ERROR:2002的解決方法
最近在啟動(dòng)mysql的時(shí)候發(fā)現(xiàn)mysql報(bào)錯(cuò)了,錯(cuò)誤代碼是2002,通過查找相關(guān)的資料發(fā)現(xiàn)是var/lib/mysql 的訪問權(quán)限問題,所以這篇文章主要介紹了mysql中異常錯(cuò)誤ERROR:2002的解決方法,需要的朋友可以參考借鑒,下面來一起看看吧。2017-03-03