MySQL/Language/User Variables

Local variables
The local variables can't be reached from outside their function or stored procedure.

They are declared like this :

Session variables

 * The ability to set variables in a statement with the := assignment operator:
 * For e.g. (@total) to calculate the total in an example, you have to have the total column first because it must be calculated before the individual percentage calculations.
 * Session variables are set for the duration of the thread.
 * In the vast majority of cases you'd use a programming language to do this sort of thing.
 * MySQL variables can be useful when working on the MySQL command line.
 * If no records are returned, the user variable will not be set for that statement.
 * A user variable set in the field list cannot be used as a condition.
 * The value of a variable is set with the SET statement or in a SELECT statement with :=


 * You can copy values retrieved by a SELECT into one or more variables:

Global variables
A global variable is visible to all users, it allows to modify the configuration files settings during the session or definitely. So when changing them, it's necessary to precise this permanent or ephemera criteria, with respectively set global and set session. Example: