Use trigger to call shell in MysSQL & MariaDB
In Windows:
Drop function if exists lib_mysqludf_sys_info;
Drop function if exists sys_get;
Drop function if exists sys_set;
Drop function if exists sys_exec;
Drop function if exists sys_eval;
Create function lib_mysqludf_sys_info RETURNS string SONAME 'lib _ mysqludf_sys.dll ';
Create function sys_get RETURNS string SONAME 'lib _ mysqludf_sys.dll ';
Create function sys_set RETURNS int SONAME 'lib _ mysqludf_sys.dll ';
Create function sys_exec RETURNS int SONAME 'lib _ mysqludf_sys.dll ';
Create function sys_eval RETURNS string SONAME 'lib _ mysqludf_sys.dll ';
Select sys_eval ('ipconfig ');
In Linux:
Execute an external program in the mysql trigger.
The procedure is as follows:
1. decompress the compressed package of the attachment.
If you do not want to compile the lib_mysqludf_sys.so file yourself, put it in mysql lib/mysql/plugin/
Directory.
2. Run chcon-t texrel_shlib_t mysql/lib/mysql/plugin/lib_mysqludf_sys.so.
3. Create a function
Drop function if exists lib_mysqludf_sys_info;
Drop function if exists sys_get;
Drop function if exists sys_set;
Drop function if exists sys_exec;
Drop function if exists sys_eval;
Create function lib_mysqludf_sys_info RETURNS string SONAME 'lib _ mysqludf_sys.so ';
Create function sys_get RETURNS string SONAME 'lib _ mysqludf_sys.so ';
Create function sys_set RETURNS int SONAME 'lib _ mysqludf_sys.so ';
Create function sys_exec RETURNS int SONAME 'lib _ mysqludf_sys.so ';
Create function sys_eval RETURNS string SONAME 'lib _ mysqludf_sys.so ';
Iv. Test
1. Prepare the sh File
Run the following command in linux
Su mysql
Mkdir/mysqlUDFtest
Cd mysqlUDFtest
Vi test. sh
#/Bin/sh
Date> testlog.txt
Chmod + x./test. sh
2. Prepare database tables and triggers
Select a database and execute the following command:
Create table test1 (a1 INT) engine = InnoDB;
Create table test2 (a2 INT) engine = InnoDB;
DELIMITER |
Drop trigger /*! 50032 if exists */'test'. 'testref' |
Create trigger 'test'. 'testref' before insert on 'test'. 'test1'
For each row BEGIN
DECLARE done int default 999;
Set done = sys_exec ("/mysqlUDFtest/test. sh ");
Insert into test2 (a2) values (2 );
END;
|
DELIMITER;
3. After inserting a piece of data into the test1 table, run the following command on the Linux Command Line: Use the root user: find/-name testlog.txt
Find the testlog.txt file.
Install LAMP (Apache with MariaDB and PHP) in CentOS/RHEL/Scientific Linux 6)
Implementation of MariaDB Proxy read/write splitting
How to compile and install the MariaDB database in Linux
Install MariaDB database using yum in CentOS
Install MariaDB and MySQL
MariaDB details: click here
MariaDB's: click here
This article permanently updates the link address: