Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 1.18 KB

README.md

File metadata and controls

63 lines (43 loc) · 1.18 KB

MySQL UDF Socket

Simple MySQL/MariaDB plugin for sending data to TCP socket and UNIX domain socket.

Installation

To compile plugin, MySQL client library has to be available. On Debian/Ubuntu it can be installed with following command.

apt install libmysqlclient-dev

Compile and install.

make
make install

Create SQL functions.

DROP FUNCTION IF EXISTS mysql_udf_socket_info;
DROP FUNCTION IF EXISTS mysql_udf_socket_send;

CREATE FUNCTION mysql_udf_socket_info RETURNS string SONAME 'mysql_udf_socket.so';
CREATE FUNCTION mysql_udf_socket_send RETURNS string SONAME 'mysql_udf_socket.so';

Usage

-- print plugin info
SELECT mysql_udf_socket_info();
-- send data to tcp socket
SELECT mysql_udf_socket_send("tcp://127.0.0.1:8080", "hello");
-- send data to unix domain socket
SELECT mysql_udf_socket_send("unix:///tmp/test.sock", "hello");

Restrictions

  • maximum data length is 128 characters
  • request/response timeout is 2 seconds

Testing

TCP socket.

echo -ne "OK" | netcat -lp 8080 -q 1

UNIX domain socket.

socat -v UNIX-LISTEN:/tmp/test.sock,mode=777,reuseaddr EXEC:"echo -n OK"

License

Licensed under MIT License.