欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

MySQL中怎么創(chuàng)建復(fù)制用戶

今天就跟大家聊聊有關(guān)MySQL 中怎么創(chuàng)建復(fù)制用戶,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

超過10余年行業(yè)經(jīng)驗(yàn),技術(shù)領(lǐng)先,服務(wù)至上的經(jīng)營(yíng)模式,全靠網(wǎng)絡(luò)和口碑獲得客戶,為自己降低成本,也就是為客戶降低成本。到目前業(yè)務(wù)范圍包括了:成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè),成都網(wǎng)站推廣,成都網(wǎng)站優(yōu)化,整體網(wǎng)絡(luò)托管,小程序定制開發(fā),微信開發(fā),成都app開發(fā),同時(shí)也可以讓客戶的網(wǎng)站和網(wǎng)絡(luò)營(yíng)銷和我們一樣獲得訂單和生意!

場(chǎng)景 1:僅在主庫(kù)創(chuàng)建復(fù)制用戶

1.主庫(kù)做一個(gè)備份并拷貝到從庫(kù)

/usr/local/mysql5732/bin/mysqldump --single-transaction --master-data=2 -B zlm -S /tmp/mysql3332.sock -p > zlm.sql  scp zlm.sql root@10.186.60.68:~

2.登陸從庫(kù)執(zhí)行導(dǎo)入

mysql> source zlm.sql

由于沒有使用參數(shù) --set-gtid-purged=off,導(dǎo)出的語(yǔ)句中會(huì)帶有 SET @@GLOBAL.GTID_PURGED='xxxx:1-xx' 并執(zhí)行,導(dǎo)入前需要先在從庫(kù)上執(zhí)行 reset master。

3.主庫(kù)創(chuàng)建復(fù)制用戶

mysql> create user repl1 identified by 'repl1';

4.從庫(kù)配置主從復(fù)制并啟動(dòng)

mysql> change master to master_host='10.186.60.62',master_port=3332,master_user='repl1',master_password='repl1',master_auto_position=1;  mysql> start slave;
MySQL 中怎么創(chuàng)建復(fù)制用戶

啟動(dòng)復(fù)制后,報(bào)了 Error 1045 的錯(cuò)誤,此處并不是密碼錯(cuò),而是沒有給復(fù)制用戶配置 replication slave 權(quán)限,在主庫(kù)上對(duì) repl1 用戶執(zhí)行賦權(quán)后(grant replication slave on *.* to repl1;),再啟動(dòng)復(fù)制就正常了。

主從復(fù)制正常以后,也會(huì)在從庫(kù)上創(chuàng)建復(fù)制用戶 repl1。

MySQL 中怎么創(chuàng)建復(fù)制用戶

從庫(kù)上并沒有創(chuàng)建過復(fù)制用戶 repl1,主從復(fù)制就正常搭建好了,為什么呢?因?yàn)?change master to 語(yǔ)句中指定的 master_user 是主庫(kù)上的復(fù)制用戶,從庫(kù)通過這個(gè)用戶連接到主庫(kù)進(jìn)行同步,當(dāng)開啟復(fù)制線程后,主庫(kù)上創(chuàng)建復(fù)制用戶的語(yǔ)句會(huì)在從庫(kù)上進(jìn)行回放,于是從庫(kù)上也會(huì)有這個(gè)復(fù)制用戶了。

結(jié)論 1

  • 搭建主從復(fù)制時(shí),在從庫(kù)創(chuàng)建復(fù)制用戶不是必須的,僅在主庫(kù)創(chuàng)建即可,復(fù)制用戶會(huì)同步到從庫(kù)。

場(chǎng)景 2:主從庫(kù)單獨(dú)創(chuàng)建復(fù)制用戶(create 語(yǔ)句)

1.主庫(kù)做一個(gè)備份并拷貝到從庫(kù)(gtid_purged=xxxx:1-23)

2.從庫(kù)執(zhí)行導(dǎo)入

3.主庫(kù)創(chuàng)建復(fù)制用戶并賦權(quán)

mysql> create user repl2 identified by 'repl2';  mysql> grant replication slave on *.* to repl2;
MySQL 中怎么創(chuàng)建復(fù)制用戶

4.從庫(kù)創(chuàng)建復(fù)制用戶

MySQL 中怎么創(chuàng)建復(fù)制用戶

由于不想在從庫(kù)上產(chǎn)生由從庫(kù) uuid 寫入的 binlog 事務(wù),此處設(shè)置了 sql_log_bin=0,使事務(wù)不被記錄到 binlog 中,原因是在數(shù)據(jù)庫(kù)管理平臺(tái)對(duì)高可用集群進(jìn)行管理時(shí),通常是不允許從庫(kù)上有主庫(kù)不存在的 GTID 事務(wù)的。

5.從庫(kù)配置主從復(fù)制并啟動(dòng)

mysql> change master to master_host='10.186.60.62',master_port=3332,master_user='repl2',master_password='repl2',master_auto_position=1; mysql> start slave;
MySQL 中怎么創(chuàng)建復(fù)制用戶

由于從庫(kù)上已經(jīng)創(chuàng)建了復(fù)制用戶,當(dāng)回放到主庫(kù)的這個(gè)事務(wù)時(shí)會(huì)報(bào) Error 1396 的錯(cuò)誤。

可以用 create user 語(yǔ)句創(chuàng)建一個(gè)重復(fù)用戶來驗(yàn)證。

MySQL 中怎么創(chuàng)建復(fù)制用戶

解析主庫(kù) binlog,啟動(dòng)復(fù)制后執(zhí)行的第一個(gè)事務(wù)就是這個(gè) 24 的創(chuàng)建用戶語(yǔ)句。

MySQL 中怎么創(chuàng)建復(fù)制用戶

結(jié)論 2

在從庫(kù)導(dǎo)入備份后并分別在主、從庫(kù)單獨(dú)創(chuàng)建復(fù)制用戶后,當(dāng)從庫(kù)執(zhí)行到創(chuàng)建用戶的事務(wù)時(shí)會(huì)導(dǎo)致復(fù)制中斷。

場(chǎng)景 3:主從庫(kù)單獨(dú)創(chuàng)建復(fù)制用戶(grant 語(yǔ)句)

1.主庫(kù)做一個(gè)備份并拷貝到從庫(kù)(gtid_purged=xxxx:1-28)

2.從庫(kù)執(zhí)行導(dǎo)入

3.主庫(kù)創(chuàng)建復(fù)制用戶

mysql> grant replication slave on *.* repl3 identified by 'repl3';
MySQL 中怎么創(chuàng)建復(fù)制用戶

4.從庫(kù)創(chuàng)建復(fù)制用戶

MySQL 中怎么創(chuàng)建復(fù)制用戶

5.從庫(kù)配置主從復(fù)制并啟動(dòng)

mysql> change master to master_host='10.186.60.62',master_port=3332,master_user='repl2',master_password='repl2',master_auto_position=1;  mysql> start slave;
MySQL 中怎么創(chuàng)建復(fù)制用戶

這次啟動(dòng)復(fù)制后并沒有報(bào)錯(cuò)。為何用 grant 語(yǔ)句創(chuàng)建用戶就可以,用 create 語(yǔ)句就不行呢?

create 與 grant 語(yǔ)句都會(huì)產(chǎn)生事務(wù)并記錄到 binlog 中,但區(qū)別是 grant 語(yǔ)句是一個(gè)近似冪等的操作,而 create 語(yǔ)句不是。

解析主庫(kù) binlog,29 和 30 都是重復(fù)執(zhí)行 grant 的事務(wù)。

MySQL 中怎么創(chuàng)建復(fù)制用戶

觀察 show slave stauts\G,從庫(kù)上也把 29,30 這兩個(gè)事務(wù)都回放掉了,重復(fù)執(zhí)行它們并不影響主從復(fù)制。

MySQL 中怎么創(chuàng)建復(fù)制用戶

但要注意的是,在 MySQL 8.0 中已經(jīng)禁止通過 grant 這種語(yǔ)法來創(chuàng)建用戶了。

MySQL 中怎么創(chuàng)建復(fù)制用戶

結(jié)論 3

  • 從庫(kù)導(dǎo)入備份并在主從庫(kù)分別使用 grant 語(yǔ)句創(chuàng)建用戶后,在從庫(kù)回放時(shí)不會(huì)導(dǎo)致復(fù)制中斷。

總結(jié)

1.根據(jù)以上驗(yàn)證結(jié)果得知,在搭建主從復(fù)制時(shí),采用多種方式創(chuàng)建復(fù)制用戶都是可行的,但有些方式存在一些限制,如:在主、從實(shí)例上分別創(chuàng)建復(fù)制用戶。雖然執(zhí)行 grant 語(yǔ)句創(chuàng)建用戶不會(huì)導(dǎo)致復(fù)制中斷,但其并不是標(biāo)準(zhǔn)的 MySQL 創(chuàng)建用戶語(yǔ)法,在 MySQL 8.0 中已被視為語(yǔ)法錯(cuò)誤,因此不推薦采用這樣的方式來搭建主從。

2.創(chuàng)建復(fù)制用戶的方式

Create 語(yǔ)句創(chuàng)建用戶時(shí)

1.主庫(kù)創(chuàng)建完復(fù)制用戶后做備份,再配置主從

2.備份后僅在主庫(kù)創(chuàng)建復(fù)制用戶,再配置主從(推薦)

3.如果要在主、從庫(kù)分別創(chuàng)建復(fù)制用戶,應(yīng)先設(shè)置 session 級(jí)別的 sql_log_bin=0,再配置主從

Grant 語(yǔ)句創(chuàng)建用戶時(shí)(MySQL 5.7 及以下版本)

1.主庫(kù)先創(chuàng)建復(fù)制用戶后備份,再配置主從

2.僅在主庫(kù)創(chuàng)建復(fù)制用戶,再配置主從(推薦)

3.主、從庫(kù)分別創(chuàng)建復(fù)制用戶,再配置主從

看完上述內(nèi)容,你們對(duì)MySQL 中怎么創(chuàng)建復(fù)制用戶有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

網(wǎng)站欄目:MySQL中怎么創(chuàng)建復(fù)制用戶
文章地址:http://chinadenli.net/article32/gpigsc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版網(wǎng)站營(yíng)銷微信小程序企業(yè)網(wǎng)站制作網(wǎng)站收錄用戶體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)