i'm using Mysql in localhost (in ubuntu and also in windows). I want to set a global variable, and I have tried in all ways but even though I get an "ok" message from mysql, then when I do the "select @var" it allways says "NULL". I've tried:
set global var=17;
set @global.var=17;
set @@var=17;
Can anyone help me?
Thanks in advance.
ps: I have the SUPER privilege.
A reference to a system variable in an expression as @@ var_name (with @@ rather than @@GLOBAL. or @@SESSION. ) returns the session value if it exists and the global value otherwise. This differs from SET @@ var_name = expr , which always refers to the session value.
System variables can be set at server startup using options on the command line or in an option file. Most of them can be changed dynamically while the server is running by means of the SET statement, which enables you to modify operation of the server without having to stop and restart it.
A user-defined schema global variable is created by using the CREATE VARIABLE SQL statement. A user-defined module global variable is created using the ADD VARIABLE or PUBLISH VARIABLE option of the ALTER MODULE SQL statement.
SUPER can be used to terminate other sessions or change how the server operates. Privileges granted for the mysql system database itself can be used to change passwords and other access privilege information: Passwords are stored encrypted, so a malicious user cannot simply read them to know the plain text password.
The variable name var
does not reference a valid system variable. The GLOBAL
and SESSION
keywords in the SET
statement are used for specifying the scope when setting MySQL system variables, not MySQL user variables.
Try for example:
SELECT @@global.net_read_timeout ;
SET GLOBAL net_read_timeout = 45 ;
SELECT @@global.net_read_timeout ;
http://dev.mysql.com/doc/refman/8.0/en/set-statement.html
http://dev.mysql.com/doc/refman/5.5/en/set-statement.html
According to the MySQL 5.0 Reference Manual:
User-defined variables are session-specific. That is, a user variable defined by one client cannot be seen or used by other clients. All variables for a given client session are automatically freed when that client exits.
You could consider using an extension like MySQL Global User Variables UDF (old archived link) to use global (persistent shared) variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With