User-Defined Variables • REDOFILE • SQL_CACHE 9.4 User-Defined Variables You can store a value in a user-defined variable in one statement and refer to it later in another statement. This enables you to pass values from one statement to another. User variables are written as  @ var_name , where the variable name  var_name  consists of alphanumeric characters,  . ,  _ , and  $ . A user variable name can contain other characters if you quote it as a string or identifier (for example,  @’my-var’ ,  @"my-var" , or  @‘my-var‘ ). User-defined variables are session specific. A user variable defined by one client cannot be seen or used by other clients. (Exception: A user with access to the Performance Schema user_variables_by_thread  table can see all user variables for all sessions.) All variables for a given client session are automatically freed when that client exits. User variable names are not case-sensitive. Names have a maximum length of 64 characters. One way to set a user-defined variable is by issuing a  SET  statement: SET @ var_name  =  expr  [, @ var_name  =  expr ] ... For  SET , either  =  or  :=  can be used as the assignment operator. User variables can be assigned a value from a limited set of data types: integer, decimal, floating-point, binary or nonbinary string, or  NULL  value. Assignment of decimal and real values does not preserve the precision or scale of the value. A value of a type other than one of the permissible types is converted to a permissible type. For example, a value having a temporal or spatial data type is converted to a binary string. A value having the  JSON  data type is converted to a string with a character set of  utf8mb4  and a collation of  utf8mb4_bin . If a user variable is assigned a nonbinary (character) string value, it has the same character set and collation as the string. The coercibility of user variables is implicit. (This is the same coercibility as for table column values.) Hexadecimal or bit values assigned to user variables are treated as binary strings. To assign a hexadecimal or bit value as a number to a user variable, use it in numeric context. For example, add 0 or use  CAST(... AS UNSIGNED) : mysql>  SET @v1 = X’41’; mysql>  SET @v2 = X’41’+0; mysql>  SET @v3 = CAST(X’41’ AS UNSIGNED); mysql>  SELECT @v1, @v2, @v3; +------+------+------+ | @v1 | @v2 | @v3 | +------+------+------+ | A | 65 | 65 | +------+------+------+ mysql>  SET @v1 = b’1000001’; mysql>  SET @v2 = b’1000001’+0; mysql>  SET @v3 = CAST(b’1000001’ AS UNSIGNED); mysql>  SELECT @v1, @v2, @v3; +------+------+------+ | @v1 | @v2 | @v3 | +------+------+------+ | A | 65 | 65 | +------+------+------+ 1912