MySQL 中 = 和 := 的区别

Difference between = and := in MySQL

MySQL这两个命令有什么区别?

它们工作得很好,结果总是一样的:

set @numRecords = (select count(*) from config);

set @numRecords := (select count(*) from config);

谢谢 大卫

引用 MySQL 5.7 参考手册,section 10.4 User-Defined Variables:

For SET, either = or := can be used as the assignment operator.

You can also assign a value to a user variable in statements other than SET. In this case, the assignment operator must be := and not = because the latter is treated as the comparison operator = in non-SET statements

"=" 不明确,可能是比较运算符。 “:=”总是被解释为赋值运算符。此信息可在 http://dev.mysql.com/doc/refman/5.7/en/assignment-operators.html .

中找到