Install MySQL Global User Variables UDF. Global User Variables UDF is a MySQL extension which helps storing global user defined variables persistently.
Go to URL: https://www.pureftpd.org/project/mysql-udf-global-user-variables/download
Click on appropriate method of download either HTTP or FTP.
wget https://download.pureftpd.org/mysql-udf-global-user-variables/global-user-variables-1.2.tar.gz
Extract downloaded tar file.
tar xzvf global-user-variables-1.2.tar.gzChange directory to extracted directory and install it.
cd global-user-variablesmake install
Now we can find udf_global_user_variables.so. We need to copy it to mysql plugin directory.
ll udf_global_user_variables.so
cp udf_global_user_variables.so /usr/lib64/mysql/plugin/
Now login to mysql and execute following command to create function.
mysql -u root -p
CREATE FUNCTION global_set RETURNS INTEGER
SONAME 'udf_global_user_variables.so';
DROP FUNCTION IF EXISTS global_get;
CREATE FUNCTION global_get RETURNS STRING
SONAME 'udf_global_user_variables.so';
DROP FUNCTION IF EXISTS global_add;
CREATE FUNCTION global_add RETURNS INTEGER
SONAME 'udf_global_user_variables.so';
Now we can set variables with following command. In case below VAR_GOLD_PRICE is a variable and 48000 is the value.
do global_set("VAR_GOLD_PRICE",48000);To read the variable value we can use following command.
select global_get("VAR_GOLD_PRICE");The value is readable globally and persistent till mysql server reboots.
No comments:
Post a Comment