mysql> SELECT we’ve not assigned any value, so the variables will assume NULL values. We can even have a hyphen (-) if we enclose the name in quotes, for example – alternative way to declare variables is by using the SELECT statement. However, it is better not to mix instead go with one convention only.Ī user variable name is an alpha-numeric and can have characters like (., _, $). While initializing the variable, we can use either a “=” or “:=” sign for assignment. See the syntax below: mysql> SET = expr1. After setting the value, it is accessible from anywhere in the script.Īn user-defined variable always begins with the sign. In MySQL, we can use the SET statement to declare a variable and also for initialization. And each has its specific way to provide a declaration. There are primarily three types of variables in MySQL. Let’s start with looking at all of them one by one. We’ll tell you the complete syntax and provide simple examples for clarity. This tutorial describes how to declare a variable (like user-defined, local, and system vars) in MySQL.