In context, such as in a SELECT statement (other than SET statements), you must use the := assignment operator, not the = operator.

If you refer to a variable that has not been initialized, its value is NULL.

User variables can be used in most contexts where expressions are allowed. However, they cannot be used where a literal value is required, such as arguments to LIMIT, and the filename in LOAD DATA INFILE (which must be a literal string).

User variables are specifically required when using EXECUTE to execute a prepared statement. Each data value given as a parameter to EXECUTE must be passed as a user variable. User variables are also used in LOAD DATA INFILE to hold data values that are to be transformed before loading into a table.

User variables are not the same as local variables that you declared in stored routines. Stored routine variables are created with a DECLARED statement and are not referred to with a leading @ character.

In MySQL 5, user variable names are not case sensitive. They were case sensitive before MySQL 5.

User variables are specific to a connection.

A user variable that has been assigned a non-binary string value has the same character set and collation as the string.