mysql gtid寻找位置_【MySQL】UUID与GTID以及如何根据GTID找寻filename和position
Open Group于1997年10月發(fā)布,UUID遵從此協(xié)議。
UUID被設(shè)計(jì)成一個(gè)在空間和時(shí)間上的唯一值。兩次調(diào)用的UUID將產(chǎn)生兩個(gè)不同的值,即使這些調(diào)用是在兩個(gè)不連接的,彼此獨(dú)立的計(jì)算機(jī)。
由一串?dāng)?shù)字表示
aaaaaaaa-bbbb-cccc
-
dddd
-
eeeeeeeeeeee
format:
mysql>?SELECT?UUID();?->?'6ccd780c-baba-1026-9564-0040f4311e29'
雖然UUID()值是唯一的,但它們不一定是不可猜測(cè)的或不可預(yù)測(cè)的。如果需要不可預(yù)測(cè)性,UUID值應(yīng)該以其他方式生成。
UUID
不基于statement replication.
The
first three numbers
are generated from a timestamp.
The
fourth number
preserves temporal uniqueness in case the timestamp value loses monotonicity (for example, due to daylight saving time).
由于夏令時(shí)導(dǎo)致的
The
fifth number
is an IEEE 802 node number that provides spatial uniqueness. A random number is substituted if the latter is not available (for example, because the host computer has no Ethernet card, or we do not know how to find the hardware address of an interface on your operating system). In this case, spatial uniqueness cannot be guaranteed. Nevertheless, a collision should have
very
low probability.
第五個(gè)數(shù)字是,它提供空間唯一一個(gè)IEEE802節(jié)點(diǎn)號(hào)。
The MAC address of an interface is taken into account only on FreeBSD and Linux. On other operating systems, MySQL uses a randomly generated 48-bit number.
uuid我在百度百科上也看到了... ...
第
1 2 3
段是與時(shí)間有關(guān)的。
time_low
、
time_mid
、
time_high_and_version
轉(zhuǎn)成
16
進(jìn)制后分別對(duì)應(yīng)第
1 2 3
段。這個(gè)時(shí)間是從
1582-10-15 00:00:00.00
到當(dāng)前時(shí)間的
100ns
值。(實(shí)際上系統(tǒng)只能取到精確
us
,再乘以
10
)。所以你短時(shí)間連續(xù)執(zhí)行的話,比較可能只有第一個(gè)值在改,實(shí)際上
1 2 3
都可能會(huì)改變。
第
4
段是你啟動(dòng)這個(gè)
MySQL
后第一次執(zhí)行
select uuid()
時(shí)的隨機(jī)數(shù),每次重啟會(huì)改變。
第
5
段是
mac
值轉(zhuǎn)過(guò)來(lái)的,同一個(gè)機(jī)器多實(shí)例的一般相同。如果
mac
值獲取不到,則是一個(gè)隨機(jī)值。
所以這個(gè)值可以認(rèn)為是每次執(zhí)行都不相同。并且不同實(shí)例之間也只有極微小概率重復(fù)。
Returns a
“
short
”
universal identifier as a 64-bit unsigned integer (rather than a string-form 128-bit identifier as returned by the
UUID()
function).
The value of
UUID_SHORT()
is guaranteed to be unique if the following conditions hold:
The
UUID_SHORT()
return value is constructed this way:
(server_id?&?255)?<
+?(server_startup_time_in_seconds?<
+?incremented_variable++;
mysql>?SELECT?UUID_SHORT();?->?92395783831158784
Note that
UUID_SHORT()
does not work with statement-based replication.
The
server_id
of the current host is unique among your set of master and slave servers
server_id
is between 0 and 255
You do not set back your system time for your server between
mysqld
restarts
與
uuid
返回固定長(zhǎng)度字符串不同,
uuid_short
的返回值是一個(gè)
unsigned long long
類型。
MySQL
啟動(dòng)后第一次執(zhí)行的值是通過(guò)
server_id << 56 + server_start_time << 24
來(lái)初始化。
server_start_time
單位是秒。
之后每次執(zhí)行都加
1
。
由于每次加
1
都會(huì)加全局
mutex
鎖,因此多線程安全,可以當(dāng)作
sequence
來(lái)用,只是初始值有點(diǎn)大。
You do not invoke
UUID_SHORT()
on average more than 16 million times per second between
mysqld
restarts
In an
INSERT ... ON DUPLICATE KEY UPDATE
statement, you can use the?VALUES(
col_name
)?function in the
UPDATE
clause to refer to column values from the
INSERT
portion of the statement. In other words,?VALUES(
col_name
)?in the
UPDATE
clause refers to the value of
col_name
that would be inserted, had no duplicate-key conflict occurred. This function is especially useful in multiple-row inserts. The
VALUES()
function is meaningful only in the?ON DUPLICATE KEY UPDATE?clause of
INSERT
statements and returns?NULL?otherwise. See
Section 13.2.5.3, “INSERT ... ON DUPLICATE KEY UPDATE Syntax”
.
mysql>?INSERT?INTO?table?(a,b,c)?VALUES?(1,2,3),(4,5,6)?->?ON?DUPLICATE?KEY?UPDATE?c=VALUES(a)+VALUES(b);
當(dāng)開啟gitd時(shí),binlog中會(huì)多出gtid event,掃描binlog就會(huì)知道GTID對(duì)應(yīng)的filename和position,主從日志落后很多,就會(huì)掃描很多binlog日志。
Previous_gtids表示這之前的binlog運(yùn)行到的GTID的位置。GTID比當(dāng)前值到就去掃這個(gè)binlog,比這個(gè)小就去掃描之前的binlog日志。
說(shuō)到切換,有的時(shí)候主庫(kù)恢復(fù)后,可能從庫(kù)還沒(méi)有應(yīng)用完,雖然我們事先準(zhǔn)備好了切換腳本,但是到這時(shí)候我們還是很猶豫的,經(jīng)歷過(guò)后會(huì)深有感觸。金融行業(yè)不允許切半同步,
總結(jié)
以上是生活随笔為你收集整理的mysql gtid寻找位置_【MySQL】UUID与GTID以及如何根据GTID找寻filename和position的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 单页扒站小工具
- 下一篇: linux系统 qq安装教程,在Linu