复制不安全的函数

发布于 2024-12-21 14:43:11 字数 82 浏览 1 评论 0原文

我的一位同事说 mysql 中的 Length() 函数复制不安全。该函数用在update语句中。这是真的吗?在编写查询并考虑复制时我们还应该考虑什么

One of my colleague says Length() function in mysql is not replication safe. This function is used in update statement. Is this true? What else should we take in to consideration when writing a query and taking replication into account

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我最亲爱的 2024-12-28 14:43:11

因为您正在复制的表也可能具有不同的字符集。主从之间的表不要求完全相同、具有相同的索引等。

mysql> create table replic(
field1 varchar(20) character set latin1,
field2 varchar(20) character set utf16,
field3 varchar(20) character set utf32);
Query OK, 0 rows affected (0.07 sec)

mysql> insert into replic values('Adrian', 'Adrian', 'Adrian');
Query OK, 1 row affected (0.07 sec)

mysql> select length(field1), length(field2), length(field3) from replic;
+----------------+----------------+----------------+
| length(field1) | length(field2) | length(field3) |
+----------------+----------------+----------------+
|              6 |             12 |             24 |
+----------------+----------------+----------------+
1 row in set (0.00 sec)

Because the table you are replicating too could have a different character set. There is no requirement for tables between master and slave to be exactly the same, have the same indexes etc.

mysql> create table replic(
field1 varchar(20) character set latin1,
field2 varchar(20) character set utf16,
field3 varchar(20) character set utf32);
Query OK, 0 rows affected (0.07 sec)

mysql> insert into replic values('Adrian', 'Adrian', 'Adrian');
Query OK, 1 row affected (0.07 sec)

mysql> select length(field1), length(field2), length(field3) from replic;
+----------------+----------------+----------------+
| length(field1) | length(field2) | length(field3) |
+----------------+----------------+----------------+
|              6 |             12 |             24 |
+----------------+----------------+----------------+
1 row in set (0.00 sec)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文