亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網(wǎng)為廣大站長(zhǎng)提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.430618.com 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

1.1 安裝前準(zhǔn)備1.2 安裝MySQL1.3 配置數(shù)據(jù)庫(kù)1.4 數(shù)據(jù)庫(kù)主從配置1.4.1 檢查配置server-id參數(shù)值1.4.2 記錄主從狀態(tài)1.4.3 啟動(dòng)主從1.4.4 驗(yàn)證主從狀態(tài)

MySQL為什么需要主從復(fù)制?

1.在一個(gè)業(yè)務(wù)復(fù)雜的系統(tǒng)中,有這樣一種場(chǎng)景,一條sql語(yǔ)句需要鎖表,導(dǎo)致暫時(shí)無(wú)法使用讀服務(wù),這將極大地影響業(yè)務(wù)的運(yùn)行。采用主從復(fù)制,主庫(kù)負(fù)責(zé)寫,從庫(kù)負(fù)責(zé)讀。這樣,即使表被鎖定在主庫(kù),也可以通過(guò)讀取從庫(kù)來(lái)保證業(yè)務(wù)的正常運(yùn)行。

2.做數(shù)據(jù)熱備。

3.建筑的擴(kuò)展。業(yè)務(wù)量越來(lái)越大,I/O訪問(wèn)的頻率對(duì)于單機(jī)來(lái)說(shuō)太高了。這時(shí)就需要多數(shù)據(jù)庫(kù)存儲(chǔ)來(lái)降低磁盤I/O訪問(wèn)的頻率,提高單機(jī)的I/O性能。

MySQL主從復(fù)制概念

MySQL主從復(fù)制意味著數(shù)據(jù)可以從一個(gè)MySQL數(shù)據(jù)庫(kù)服務(wù)器主節(jié)點(diǎn)復(fù)制到一個(gè)或多個(gè)從節(jié)點(diǎn)。MySQL默認(rèn)采用異步復(fù)制,讓從節(jié)點(diǎn)不用一直訪問(wèn)主服務(wù)器來(lái)更新自己的數(shù)據(jù),數(shù)據(jù)可以在遠(yuǎn)程連接上更新。從節(jié)點(diǎn)可以復(fù)制主數(shù)據(jù)庫(kù)中的所有數(shù)據(jù)庫(kù)或特定數(shù)據(jù)庫(kù)或特定表。

MySQL 主從復(fù)制主要用途

1、讀寫分離

2、數(shù)據(jù)實(shí)時(shí)備份,當(dāng)系統(tǒng)中某個(gè)節(jié)點(diǎn)出現(xiàn)故障的時(shí)候,方便切換

3、高可用HA

4、架構(gòu)擴(kuò)展

MySQL主從形式


 


 


 


 

原理


 

主從復(fù)制過(guò)程


 


 

以下雙主配置架構(gòu)


 

MySQL安裝

MySQL安裝需要依次完成:

· 安裝前準(zhǔn)備

· 安裝MYSQL

· 配置MySQL數(shù)據(jù)庫(kù)

· 數(shù)據(jù)庫(kù)主從配置

安裝介質(zhì)包包括:mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz,位于安裝介質(zhì)包的mysql文件目錄下,本次安裝采用解壓式安裝。

MySQL安裝目錄為/usr/local/mysql。

MySQL數(shù)據(jù)文件存放目錄為/data。

MySQL安裝以主機(jī)pmondbs01為例。

在/tmp目錄創(chuàng)建plugin目錄,用于臨時(shí)存放MySQL安裝介質(zhì)。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

mkdir -p /tmp/plugin

在/tmp/下創(chuàng)建plugin目錄

執(zhí)行示意

[root@pmondbs01 ~] # mkdir /tmp/plugin

然后通過(guò)FTP方式上傳mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz。

MySQL安裝采用解壓式安裝,即解壓之后通過(guò)修改配置文件的方式完成MySQL部署。

1. 數(shù)據(jù)庫(kù)文件部署

使用命令

執(zhí)行順序

命令

說(shuō)明

1

mkdir /usr/local/mysql

創(chuàng)建MySQL安裝目錄

2

cd /tmp/plugin/

進(jìn)入MySQL安裝介質(zhì)路徑/tmp/plugin

3

tar -zxf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql

解壓mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz到/usr/local/mysql

4

mv /usr/local/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/* /usr/local/mysql/

移動(dòng)/usr/local/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/下所有文件到/usr/local/mysql/

5

rm -rf /usr/local/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/

刪除/usr/local/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/目錄

執(zhí)行示意

[root@pmondbs01 ~] # mkdir /usr/local/mysql

[root@pmondbs01 ~] # tar -zxf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql

[root@pmondbs01 ~] # mv /usr/local/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/* /usr/local/mysql/

[root@pmondbs01 ~] # rm -rf /usr/local/mysql/mysql-5.7.22-linux-glibc2.12-x86_64/

2. 創(chuàng)建數(shù)據(jù)文件目錄及數(shù)據(jù)庫(kù)專屬用戶賬號(hào)

數(shù)據(jù)文件目錄為/data,數(shù)據(jù)庫(kù)專屬用戶為mysql和用戶組為mysql,需要將MySQL安裝目錄和數(shù)據(jù)文件所在讀寫權(quán)限賦予用戶mysql。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

mkdir -p /data/

創(chuàng)建數(shù)據(jù)文件目錄

2

groupadd mysql

創(chuàng)建mysql用戶組

3

useradd -g mysql mysql

創(chuàng)建mysql用戶庫(kù)

4

chmod -R 755 /usr/local/mysql/

賦予MySQL安裝目錄 /usr/local/mysql/ 775權(quán)限

5

chown -R mysql.mysql /usr/local/mysql/

改變MySQL安裝目錄屬主為mysql

6

chmod -R 755 /data/

賦予MySQL數(shù)據(jù)文件目錄 /data/ 775權(quán)限

7

chown -R mysql.mysql /data/

改變MySQL數(shù)據(jù)文件目錄屬主為mysql

執(zhí)行示意

[root@pmondbs01 ~] # mkdir -p /data/

[root@pmondbs01 ~] # groupadd mysql

[root@pmondbs01 ~] # useradd -g mysql mysql

[root@pmondbs01 ~] # chmod -R 755 /usr/local/mysql/

[root@pmondbs01 ~] # chown -R mysql.mysql /usr/local/mysql/

[root@pmondbs01 ~] # chmod -R 755 /data/

[root@pmondbs01 ~] # chown -R mysql.mysql /data/

3. 主MySQL配置文件

將安裝介質(zhì)中conf文件夾下my.cnf通過(guò)FTP方式上傳至/etc/下,然后修改以下參數(shù)配置。

參數(shù)設(shè)置詳情為:

參數(shù)所屬節(jié)點(diǎn)

參數(shù)

mysqld

server-id

1

port

3306

basedir

/usr/local/mysql

datadir

/data/

使用命令

執(zhí)行順序

命令

說(shuō)明

1

vi /etc/my.cnf

編輯MySQL配置文件

2

[mysqld]

server-id=1

port=3306

basedir=/usr/local/mysql

datadir= /data/

[mysqld]參數(shù)節(jié)點(diǎn),需要修改=號(hào)后面的值

執(zhí)行示意

[root@pmondbs01 ~] # vi /etc/my.cnf

[mysqld]

server-id=1

port=3306

basedir=/usr/local/mysql

datadir= /data/

4. 若啟用MySQL主從配置,則需要修改備庫(kù)MySQL配置文件my.cnf,以pmondbs02為例,需要將參數(shù)server-id的值修改為10,其他配置和主庫(kù)配置保持一致。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

vi /etc/my.cnf

編輯MySQL配置文件

2

[mysqld]

server-id=10

[mysqld]參數(shù)節(jié)點(diǎn),需要修改=號(hào)后面的值

執(zhí)行示意

注意:以下操作在從MySQL數(shù)據(jù)庫(kù)上執(zhí)行,比如從MySQL數(shù)據(jù)庫(kù)在pmondbs02主機(jī)上。

[root@pmondbs02 ~] # vi /etc/my.cnf

[mysqld]

server-id=10

注意:在備MySQL數(shù)據(jù)庫(kù)上操作完畢。

5. 配置MySQL服務(wù)隨操作系統(tǒng)啟動(dòng),

配置MySQL服務(wù)隨操作系統(tǒng)啟動(dòng),需要從MySQL安裝目錄復(fù)制MySQL啟動(dòng)腳本到/etc/init.d目錄下,文件名為mysqld。然后在啟動(dòng)腳本中添加MySQL的安裝目錄和數(shù)據(jù)文件目錄,確認(rèn)無(wú)誤后保存,賦予mysqld文件755權(quán)限,然后使用chkconfig設(shè)置MySQL隨操作系統(tǒng)啟動(dòng)。

MySQL啟動(dòng)腳本位于/usr/local/mysql/support-files/目錄下,文件名為mysql.server。

MySQL啟動(dòng)腳本中需要修改:basedir=/usr/local/mysql和datadir=/data/。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

cp -af /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

復(fù)制MySQL啟動(dòng)腳本mysql.server到/etc/init.d/目錄下,文件名為mysqld

2

vi /etc/init.d/mysqld

編輯/etc/init.d/mysqld文件

3

basedir=/usr/local/mysql

datadir=/data/

輸入內(nèi)容

4

chmod 755 /etc/init.d/mysqld

賦予MySQL啟動(dòng)腳本755權(quán)限

5

chkconfig --add mysqld

添加MySQL啟動(dòng)隨系統(tǒng)啟動(dòng)

6

chkconfig --level 345 mysqld on

修改MySQL啟動(dòng)級(jí)別

執(zhí)行示意

[root@pmondbs01 ~]# cp -af /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@pmondbs01 ~]# vi /etc/init.d/mysqld

# If you change base dir, you must also change datadir. These may get

# overwritten by settings in the MySQL configuration files.

basedir=/usr/local/mysql

datadir=/data/

[root@pmondbs01 ~]# chmod 755 /etc/init.d/mysqld

[root@pmondbs01 ~]# chkconfig --add mysqld

[root@pmondbs01 ~]# chkconfig --level 345 mysqld on

6. 初始化MySQL數(shù)據(jù)庫(kù)

在MySQL安裝目錄進(jìn)入bin目錄下執(zhí)行帶上參數(shù)執(zhí)行mysqld命令完成MySQL數(shù)據(jù)庫(kù)初始化。

mysqld命令初始化數(shù)據(jù)庫(kù)參數(shù)為--initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

cd /usr/local/mysql/bin

進(jìn)入MySQL的bin目錄

2

./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data

帶參數(shù)執(zhí)行mysqld

執(zhí)行示意

[root@pmondbs01 ~]# cd /usr/local/mysql/bin

[root@pmondbs01 ~]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data

MySQL5.7以后root賬號(hào)的密碼采用啟動(dòng)MySQL后生成隨機(jī)密碼的方式,所以修改MySQL的root賬號(hào)密碼需要完成以下幾步操作。

1. 啟動(dòng)MySQL服務(wù)

啟動(dòng)MySQL服務(wù)命令為service mysqld start。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

service mysqld start

啟動(dòng)MySQL服務(wù)

2

ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sockComment by 小言: ln: 無(wú)法創(chuàng)建符號(hào)鏈接"/var/lib/mysql/mysql.sock": 沒有那個(gè)文件或目錄

創(chuàng)建/tmp/mysql.sock軟鏈接到/var/lib/mysql/mysql.sock

執(zhí)行示意

[root@pmondbs01 ~]# service mysqld start

[root@pmondbs01 ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

2. 查詢r(jià)oot賬號(hào)臨時(shí)密碼

檢索在MySQL數(shù)據(jù)文件目錄的mysql-error.log文件可以查找到密碼,密碼檢索關(guān)鍵字為“password”,關(guān)鍵字“password”所在行“A temporary password is generated for root@localhost:”后面為臨時(shí)密碼,比如“swf88nhHgx(z”為臨時(shí)密碼。該臨時(shí)密碼作為第一次使用root賬號(hào)登錄數(shù)據(jù)庫(kù)使用的密碼。

注:MySQLroot賬號(hào)的臨時(shí)密碼是隨機(jī)生成的每次安裝都會(huì)產(chǎn)生不同的密碼。

mysql-error.log位于/data/下。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

cat /data/mysql-error.log|grep password

讀取mysql-error.log并過(guò)濾關(guān)鍵password

2

2020-01-08T15:48:42.569059+08:00 1 [Note] A temporary password is generated for root@localhost: swf88nhHgx(z

輸出

執(zhí)行示意

[root@pmondbs01 ~]# cat /data/mysql-error.log|grep password

2020-01-08T15:48:42.569059+08:00 1 [Note] A temporary password is generated for root@localhost: swf88nhHgx(z

3. 修改root賬號(hào)密碼

登錄MySQL數(shù)據(jù)庫(kù),修改root賬號(hào)密碼為password,創(chuàng)建可以從任何主機(jī)訪問(wèn)數(shù)據(jù)庫(kù)的root賬號(hào)并設(shè)置密碼為password,用于管理數(shù)據(jù)庫(kù);創(chuàng)建可以從任何主機(jī)訪問(wèn)數(shù)據(jù)庫(kù)的同步賬號(hào)repl并設(shè)置密碼為repl,用于MySQL數(shù)據(jù)庫(kù)主從同步,并給賬號(hào)賦予相應(yīng)權(quán)限。

登錄MySQL數(shù)據(jù)庫(kù)命令為mysql -uroot -p,回車之后輸入密碼,密碼為上一步操作查詢到的臨時(shí)密碼swf88nhHgx(z。

創(chuàng)建root賬號(hào)并設(shè)置密碼為password的SQL語(yǔ)句為:“create user root@'%' identified by 'password';”

授權(quán)root賬號(hào)具有所有權(quán)限的SQL語(yǔ)句為grant all privileges on *.* to root@'%';

修改root賬號(hào)密碼為password的SQL語(yǔ)句為alter user root@localhost identified by 'password';

使用命令

執(zhí)行順序

命令

說(shuō)明

1

cd /usr/local/mysql/bin

進(jìn)入MySQL安裝目錄的bin目錄下

2

./mysql -uroot -p

啟動(dòng)MySQL客戶端

3

swf88nhHgx(z

輸入root賬號(hào)密碼,進(jìn)入MySQL命令行客戶端。root賬號(hào)密碼在上一步驟中獲取。

4

alter user root@localhost identified by 'password';

修改root賬號(hào)密碼為password

5

create user root@'%' identified by 'password';

創(chuàng)建可以從任何主機(jī)訪問(wèn)數(shù)據(jù)庫(kù)的root賬號(hào)并設(shè)置密碼為password

6

grant all privileges on *.* to root@'%';

授權(quán)可以從任何主機(jī)訪問(wèn)數(shù)據(jù)庫(kù)的root賬號(hào)所有權(quán)限

7

flush privileges;

刷新數(shù)據(jù)庫(kù)權(quán)限

12

flush privileges;

刷新數(shù)據(jù)庫(kù)權(quán)限

13

create user repl@'%' identified by 'repl';

創(chuàng)建可以從任何主機(jī)訪問(wèn)數(shù)據(jù)庫(kù)的repl賬號(hào)并設(shè)置密碼為reple

14

grant replication slave on *.* to 'repl'@'%';

授權(quán)可以從任何主機(jī)訪問(wèn)數(shù)據(jù)庫(kù)的repl賬號(hào)replication slave權(quán)限

15

flush privileges;

刷新數(shù)據(jù)庫(kù)權(quán)限

16

quit;

退出MySQL命令行客戶端

執(zhí)行示意

[root@localhost ~]# cd /usr/local/mysql/bin

[root@pmondbs01 bin]# ./mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 4

Server version: 5.7.22-log

Copyright (c) 2000, 2018, 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 [(none)]>alter user root@localhost identified by 'password';

Query OK, 0 rows affected (0.02 sec)

MySQL [(none)]> create user root@'%' identified by 'password';

Query OK, 0 rows affected (0.05 sec)

MySQL [(none)]> grant all privileges on *.* to root@'%';

Query OK, 0 rows affected (0.06 sec)

MySQL [(none)]> flush privileges;

Query OK, 0 rows affected (0.05 sec)

MySQL [(none)]> create user 'zabbix'@localhost identified by 'zabbix';

Query OK, 0 rows affected (0.06 sec)

MySQL [(none)]> create user 'zabbix'@'%' identified by 'zabbix';

Query OK, 0 rows affected (0.06 sec)

MySQL [(none)]> grant all privileges on *.* to 'zabbix'@localhost;

Query OK, 0 rows affected, 1 warning (0.05 sec)

MySQL [(none)]> grant all privileges on *.* to 'zabbix'@'%';

Query OK, 0 rows affected (0.05 sec)

MySQL [(none)]> flush privileges;

Query OK, 0 rows affected (0.03 sec)

MySQL [(none)]> create user repl@'%' identified by 'repl';

Query OK, 0 rows affected (0.04 sec)

MySQL [(none)]> grant replication slave on *.* to 'repl'@'%';

Query OK, 0 rows affected (0.05 sec)

MySQL [(none)]> flush privileges;

Query OK, 0 rows affected (0.03 sec)

MySQL [(none)]> quit;

Bye

[root@localhost bin]#

兩臺(tái)MySQL數(shù)據(jù)庫(kù)做主從配置,假設(shè)情況如下:

主機(jī)名

IP地址

角色

參數(shù)server-id

同步用戶名

同步密碼

pmondbs01

.81.49

1

repl

repl

pmondbs02

.81.50

10

repl

repl

數(shù)據(jù)庫(kù)基本配置參考7.2、7.3。

數(shù)據(jù)庫(kù)主從配置參數(shù)server-id的值務(wù)必不能一樣。

參數(shù)server-id的值與前面章節(jié)保持一致。

檢查.81.49并設(shè)置server-id參數(shù)值。

[root@pmondbs01 bin]# vi /etc/my.cnf

[mysqld]

server-id = 1

如果server-id參數(shù)值未設(shè)置為1,設(shè)置之后重啟MySQL數(shù)據(jù)庫(kù),設(shè)置server-id參數(shù)值參考7.2安裝MySQL。

檢查.81.50并設(shè)置server-id參數(shù)值。

[root@pmondbs02 bin]# vi /etc/my.cnf

[mysqld]

server-id = 10

如果server-id參數(shù)值未設(shè)置為10,設(shè)置之后重啟MySQL數(shù)據(jù)庫(kù),設(shè)置server-id參數(shù)值參考7.2安裝MySQL。

重啟MySQL使用命令

執(zhí)行順序

命令

說(shuō)明

1

service mysqld stop

停止MySQL

2

service mysqld start

啟動(dòng)MySQL

執(zhí)行示意,以在服務(wù)器pmondbs01上為例

[root@pmondbs01 ~] # service mysql stop

[root@pmondbs01 ~] # service mysql start

1. 登錄81.49 MySQL數(shù)據(jù)庫(kù),執(zhí)行show master status,檢查并記錄Master狀態(tài)。記錄File、Position,F(xiàn)ile為mysql-bin.000003,Position為194。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

cd /usr/local/mysql/bin

進(jìn)入MySQL安裝目錄的bin目錄下

2

./mysql -uroot -p

啟動(dòng)MySQL客戶端

3

password

輸入root賬號(hào)密碼,進(jìn)入MySQL命令行客戶端。

4

show master status;

查看Master狀態(tài)

執(zhí)行示意

[root@pmondbs01 ~]# cd /usr/local/mysql/bin

[root@pmondbs01 bin]# ./mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 4

Server version: 5.7.22-log

Copyright (c) 2000, 2018, 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 [(none)]>show master status;

+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+

| mysql-bin.000002 | 3842 | | | 15aa5540-31fc-11ea-9d2d-84139f30d4bd:1-14,

4a871e1c-31eb-11ea-81b2-84139f30d4f5:13-15 |

+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

MySQL [(none)]>

2. 登錄.81.50 MySQL數(shù)據(jù)庫(kù),執(zhí)行show master status,檢查并記錄Master狀態(tài)。記錄File、Position,F(xiàn)ile為mysql-bin.000003,Position為194。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

cd /usr/local/mysql/bin

進(jìn)入MySQL安裝目錄的bin目錄下

2

./mysql -uroot -p

啟動(dòng)MySQL客戶端

3

password

輸入root賬號(hào)密碼,進(jìn)入MySQL命令行客戶端。

4

show master status;

查看Master狀態(tài)

執(zhí)行示意

[root@pmondbs02 ~]# cd /usr/local/mysql/bin

[root@pmondbs02 bin]# ./mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 4

Server version: 5.7.22-log

Copyright (c) 2000, 2018, 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 [(none)]>show master status;

+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+

| mysql-bin.000003 | 3042 | | | 15aa5540-31fc-11ea-9d2d-84139f30d4bd:13-14,

4a871e1c-31eb-11ea-81b2-84139f30d4f5:1-15 |

+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

MySQL [(none)]>

master_log_file和master_log_pos參數(shù)來(lái)自7.4.2記錄的File和Position。

登錄.81.49MySQL數(shù)據(jù)庫(kù)之后執(zhí)行“change master to master_host='.4.81.50',master_user='repl',master_password='repl',master_log_file='mysql-bin.000003',master_log_pos=3042;”。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

cd /usr/local/mysql/bin

進(jìn)入MySQL安裝目錄的bin目錄下

2

./mysql -uroot -p

啟動(dòng)MySQL客戶端

3

password

輸入root賬號(hào)密碼,進(jìn)入MySQL命令行客戶端。

4

change master to master_host='81.50',master_user='repl',master_password='repl',master_log_file='mysql-bin.000003',master_log_pos=194;

查看Master狀態(tài)

5

start slave;

啟動(dòng)主從同步

執(zhí)行示意

MySQL [(none)]> change master to master_host='.81.50',master_user='repl',master_password='repl',master_log_file='mysql-bin.000003',master_log_pos=3042;

MySQL [(none)]>start slave;

登錄.81.50MySQL數(shù)據(jù)庫(kù)之后執(zhí)行“change master to master_host='.81.49',master_user='repl',master_password='repl',master_log_file='mysql-bin.000002',master_log_pos=3842;”。

使用命令

執(zhí)行順序

命令

說(shuō)明

1

cd /usr/local/mysql/bin

進(jìn)入MySQL安裝目錄的bin目錄下

2

./mysql -uroot -p

啟動(dòng)MySQL客戶端

3

password

輸入root賬號(hào)密碼,進(jìn)入MySQL命令行客戶端。

4

change master to master_host='.81.49',master_user='repl',master_password='repl',master_log_file='mysql-bin.000003',master_log_pos=194;

查看Master狀態(tài)

5

start slave;

啟動(dòng)主從同步

執(zhí)行示意

MySQL [(none)]> change master to master_host='.81.49',master_user='repl',master_password='repl',master_log_file='mysql-bin.000002',master_log_pos=3842;

MySQL [(none)]>start slave;

登錄.81.49MySQL數(shù)據(jù)庫(kù)執(zhí)行命令show slave status G;,查看Slave_IO_Running、Slave_SQL_Running是否為Yes,為Yes表示主從正常執(zhí)行。

執(zhí)行命令:

show slave status G;

MySQL [(none)]>show slave status G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: .81.50

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000002

Read_Master_Log_Pos: 3842

Relay_Log_File: mysql-relay.000002

Relay_Log_Pos: 764

Relay_Master_Log_File: mysql-bin.000002

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: 3842

Relay_Log_Space: 967

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: 10

Master_UUID: 15aa5540-31fc-11ea-9d2d-84139f30d4bd

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: 15aa5540-31fc-11ea-9d2d-84139f30d4bd:13-14

Executed_Gtid_Set: 15aa5540-31fc-11ea-9d2d-84139f30d4bd:13-14,

4a871e1c-31eb-11ea-81b2-84139f30d4f5:1-15

Auto_Position: 0

Replicate_Rewrite_DB:

Channel_Name:

Master_TLS_Version:

1 row in set (0.00 sec)

ERROR: No query specified

MySQL [(none)]>

登錄.81.50MySQL數(shù)據(jù)庫(kù)執(zhí)行命令show slave status G;,查看Slave_IO_Running、Slave_SQL_Running是否為Yes,為Yes表示主從正常執(zhí)行。

MySQL [(none)]>show slave status G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: .81.49

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000003

Read_Master_Log_Pos: 3842

Relay_Log_File: mysql-relay.000002

Relay_Log_Pos: 1025

Relay_Master_Log_File: mysql-bin.000003

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: 3842

Relay_Log_Space: 1228

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: 1

Master_UUID: 4a871e1c-31eb-11ea-81b2-84139f30d4f5

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: 4a871e1c-31eb-11ea-81b2-84139f30d4f5:13-15

Executed_Gtid_Set: 15aa5540-31fc-11ea-9d2d-84139f30d4bd:1-14,

4a871e1c-31eb-11ea-81b2-84139f30d4f5:13-15

Auto_Position: 0

Replicate_Rewrite_DB:

Channel_Name:

Master_TLS_Version:

1 row in set (0.00 sec)

ERROR:

No query specified

MySQL [(none)]>zh

分享到:
標(biāo)簽:MySql
用戶無(wú)頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過(guò)答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫(kù),初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績(jī)?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績(jī)?cè)u(píng)定