日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MySQL从库的列类型不一致导致的复制异常问题

發布時間:2024/4/13 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL从库的列类型不一致导致的复制异常问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

官方文檔:https://dev.mysql.com/doc/refman/5.6/en/replication-features-differing-tables.html


slave_type_conversions??這個參數在mysql5.5.3?引入,目的是啟用row?格式的bin-log?的時候,如果主從的column?的數據類型不一致,會導致復制失敗,mysql5.5.3?之后支持,主庫是int?從庫是bigint?這種類型的復制,

這個參數的意義就是控制些類型轉換容錯性。

?

如果從庫的字段類型范圍比主庫類型大,那么設置slave_type_conversions=ALL_NON_LOSSY后復制沒有問題的。

如果從庫類型比主庫類型小,比如從int?復制到tinyint?,雖然可以通過設置slave_type_conversions=ALL_LOSSY,ALL_NON_LOSSY讓主從不出問題,但是實際上會造成數據丟失的風險。

?

幾種值的設置:

??? ALL_LOSSY允許數據截斷

??? ALL_NON_LOSSY不允許數據截斷,如果從庫類型大于主庫類型,是可以復制的,反過了,就不行了,從庫報復制錯誤,復制終止。

??? ALL_LOSSY,ALL_NON_LOSSY:?所有允許的轉換都會執行,而不管是不是數據丟失。

????空值(不設置)要求主從庫的數據類型必須嚴格一致,否則都報錯。

Mode

Effect

ALL_LOSSY

In this mode, type conversions that would mean loss of information are ?permitted.

This does not ?imply that non-lossy conversions are permitted, merely that only cases ?requiring either lossy conversions or no conversion at all are permitted; for ?example, enabling?only?this mode permits an?INT?column to be converted to?TINYINT?(a lossy conversion), but not a?TINYINT?column to an?INT?column (non-lossy). Attempting ?the latter conversion in this case would cause replication to stop with an ?error on the slave.

ALL_NON_LOSSY

This mode permits conversions that do not require truncation or other ?special handling of the source value; that is, it permits conversions where ?the target type has a wider range than the source type.?【確保從庫的列類型更寬泛些也不會導致復制報錯】

Setting this ?mode has no bearing on whether lossy conversions are permitted; this is ?controlled with the?ALL_LOSSY?mode. If ?only?ALL_NON_LOSSY?is set, ?but not?ALL_LOSSY, then ?attempting a conversion that would result in the loss of data (such as?INT?to?TINYINT, or?CHAR(25)?to?VARCHAR(20)) causes the slave to stop with an ?error.

ALL_LOSSY,ALL_NON_LOSSY

When this mode is set, all supported type conversions are permitted, whether ?or not they are lossy conversions.

ALL_SIGNED

Treat promoted integer types as signed values (the default behavior).

ALL_UNSIGNED

Treat promoted integer types as unsigned values.

ALL_SIGNED,ALL_UNSIGNED

Treat promoted integer types as signed if possible, otherwise as ?unsigned.

[empty]

When?slave_type_conversions?is not ?set, no attribute promotion or demotion is permitted; this means that all ?columns in the source and target tables must be of the same types.

This mode is the default.


生產環境一個案例:

從庫是有個oracle系統去查數據的,原先從庫的cp_shop_activity表示utf8mb4字符集,oracle不支持。因此在這個從庫上手動修改了mode字段的字符類型為varchar(200) utf8,修改后的字段類型如下圖:


但是沒幾天后,發現主從復制報錯了,錯誤碼1677。從庫上記錄的錯誤日志如下:


我們看下主庫的mode字段是varchar(50),從庫的mode字段是varchar(200)


在從庫設置:

stop slave;

set global slave_type_conversions=ALL_NON_LOSSY;??

#?默認slave_type_conversions為空,表示強制從庫和主庫的字段類型一致,不然就停止復制。設置為ALL_NON_LOSSY就稍微寬泛些同時確保不會造成類型轉換的問題。

start slave;

show slave status\G ?

這樣即可解決這個問題。

?










本文轉自 lirulei90 51CTO博客,原文鏈接:http://blog.51cto.com/lee90/1913061,如需轉載請自行聯系原作者

總結

以上是生活随笔為你收集整理的MySQL从库的列类型不一致导致的复制异常问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。