The only way this can happen (in a client session) - and how it happens to me from time to time - you get a bit through a short timeout on the client connection. This happens as follows:
mysql> set @a = 10;
mysql> [wait for N+1 minutes, where N is the client timeout]
mysql> select @a;
+------+
| NULL |
+------+
| NULL |
+------+
1 row in set (0.00 sec)
You must initialize your variables and use them in a continuous client session. When the session leaves, you lose all your variables.
, , , ; , "SET..." "SELECT..." . .