MysSQL & amp; MariaDB uses trigger to call shell

Source: Internet
Author: User
Tags call shell

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.