search
HomeDatabaseMysql TutorialMysSQLMariaDB用trigger调用shell

MysSQLMariaDB用trigger调用shell

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');

Linux环境下:

在mysql的触发器中执行一个外部程序。

步骤如下:

一、解压附件的压缩包之后

如果不想自己编译的话,,把lib_mysqludf_sys.so文件放到 mysql的lib/mysql/plugin/

目录下。

二、执行chcon -t texrel_shlib_t mysql/lib/mysql/plugin/lib_mysqludf_sys.so

三、创建函数

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';
四、测试

1、准备sh文件
在linux系统中执行下面的命令
su mysql
mkdir /mysqlUDFtest

cd mysqlUDFtest
vi test.sh

#/bin/sh
date > testlog.txt

chmod +x ./test.sh
2、准备数据库表和触发器
选择一个数据库执行如下命令:

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、向test1表中插入一条数据后,请在Linux命令行:用root用户,执行以下命令:find / -name testlog.txt

查找testlog.txt文件。

在 CentOS/RHEL/Scientific Linux 6 下安装 LAMP (Apache with MariaDB and PHP)

MariaDB Proxy读写分离的实现

Linux下编译安装配置MariaDB数据库的方法

CentOS系统使用yum安装MariaDB数据库

安装MariaDB与MySQL并存

MariaDB 的详细介绍:请点这里
MariaDB 的下载地址:请点这里

本文永久更新链接地址:

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
使用PHP连接MariaDB数据库使用PHP连接MariaDB数据库May 17, 2023 am 08:24 AM

MariaDB是一种开源的关系型数据库管理系统,它是MySQL的一个分支。PHP作为一种开源的服务器端脚本语言,被广泛应用于Web开发中。在很多Web开发项目中,需要使用PHP连接到MariaDB数据库,以便在Web应用程序中存储和检索数据。这篇文章将介绍如何使用PHP编写代码来连接MariaDB数据库。一、安装MariaDB服务器在使用PHP连接Maria

如何使用PDO连接到MariaDB数据库如何使用PDO连接到MariaDB数据库Jul 28, 2023 pm 02:49 PM

如何使用PDO连接到MariaDB数据库一、简介PDO(PHPDataObjects)是PHP中用来访问数据库的一个轻量级的抽象层。它为开发者提供了一组统一的接口来连接和操作不同类型的数据库,包括MariaDB、MySQL、SQLite等。本文将介绍如何使用PDO来连接到MariaDB数据库,并给出示例代码。二、安装和配置在使用PDO连接到MariaDB

一文详解MariaDB与MySQL的区别一文详解MariaDB与MySQL的区别Mar 09, 2023 am 11:39 AM

本篇文章给大家带来了关于MariaDB和MySQL的相关知识,其中主要跟大家聊一聊MariaDB与MySQL的区别都有哪些,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

使用Docker Compose、Nginx和MariaDB优化PHP应用程序的网络性能使用Docker Compose、Nginx和MariaDB优化PHP应用程序的网络性能Oct 12, 2023 pm 12:49 PM

使用DockerCompose、Nginx和MariaDB优化PHP应用程序的网络性能简介:在当今互联网时代,网络性能对于Web应用程序的稳定性和响应速度至关重要。为了提高PHP应用程序的网络性能,我们可以使用容器化技术DockerCompose、高效的Web服务器Nginx和稳定的数据库MariaDB。本文将详细介绍如何使用这些工具来优化PHP应用的网

如何在 Debian 12 上安装 MariaDB数据库如何在 Debian 12 上安装 MariaDB数据库Feb 20, 2024 pm 02:24 PM

MariaDB是一个开源多线程的关系数据库管理系统,是MySQL的替代品。MariaDB是Debian中MySQL的默认替换方案。本教程介绍如何在Debian12上安装MariaDB。准备条件1、一台安装了Debian12的VPS虚拟机(推荐您购买一台阿里云VPS或者腾讯云VPS虚拟主机,如果你更喜欢国外服务器,推荐你尝试Vultr上的VPS,注册即送$50美元体验,性价比非常高),当然你自己电脑或者虚拟机中也可以。2、如果使用VPS,基于安全考虑,建议使用非root账号,可以在Debian12

Docker Compose、Nginx和MariaDB的最佳实践:部署PHP应用程序的监控与优化Docker Compose、Nginx和MariaDB的最佳实践:部署PHP应用程序的监控与优化Oct 12, 2023 pm 02:19 PM

DockerCompose、Nginx和MariaDB的最佳实践:部署PHP应用程序的监控与优化引言:在现代应用程序开发中,容器化已经成为一种流行的方式,能够帮助我们更好地管理和部署应用程序。而DockerCompose则是一种用于定义和运行多个容器的工具,它能够简化应用程序的部署和管理过程。本文将介绍如何使用DockerCompose结合Nginx和

使用Docker Compose、Nginx和MariaDB优化PHP应用程序的性能问题使用Docker Compose、Nginx和MariaDB优化PHP应用程序的性能问题Oct 12, 2023 pm 12:55 PM

使用DockerCompose、Nginx和MariaDB优化PHP应用程序的性能问题在开发和部署PHP应用程序时,经常会遇到性能问题。为了解决这些问题,我们可以利用DockerCompose、Nginx和MariaDB来优化应用程序的性能。DockerCompose是一个用于定义和管理多个Docker容器的工具。它可以帮助我们轻松地创建和运行多个容器

使用Docker Compose、Nginx和MariaDB实现PHP应用程序的安全加固使用Docker Compose、Nginx和MariaDB实现PHP应用程序的安全加固Oct 12, 2023 am 09:02 AM

使用DockerCompose、Nginx和MariaDB实现PHP应用程序的安全加固随着网络攻击和数据泄漏的频繁发生,保护应用程序和数据库的安全变得愈发重要。在PHP应用程序中,使用DockerCompose、Nginx和MariaDB可以实现安全加固,并提供一定的安全保护措施。本文将介绍如何使用这些工具进行安全加固,并提供一些代码示例。使用Docke

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.