S
S
sbh2020-03-07 12:10:55
MySQL
sbh, 2020-03-07 12:10:55

How to parse data by trigger before mysql insert?

Good afternoon.
Requests receive data of the form:

07-Mar-2020 18:11:34.456 queries: info: client 55.44.33.22#49230 (111.222.333.444.in-addr.arpa): view All_View: query: 111.111.111.111.in-addr.arpa IN PTR + (22.22.22.22)


It is necessary to parse the data and write to the logs table, respectively, the data
07-Mar-2020 18:11:34.456
55.44.33.22
111.111.111.111.in-addr.arpa

into the fields:
date
client
request

It would be optimal to do this using the MySQL Before Insert trigger

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valentyn, 2020-03-07
@rotarepmipoleved

SUBSTRING_INDEX(string, delimiter, number) ( https://www.w3schools.com/sql/func_mysql_substring...

SELECT
  SUBSTRING_INDEX("07-Mar-2020 18:11:34.456 queries: info: client 55.44.33.22#49230 (111.222.333.444.in-addr.arpa): view All_View: query: 111.111.111.111.in-addr.arpa IN PTR + (22.22.22.22)", " queries:", 1) as `date`,
  SUBSTRING_INDEX(
    SUBSTRING_INDEX("07-Mar-2020 18:11:34.456 queries: info: client 55.44.33.22#49230 (111.222.333.444.in-addr.arpa): view All_View: query: 111.111.111.111.in-addr.arpa IN PTR + (22.22.22.22)", "#", 1),
    " ",
    -1
  ) as `client`,
  SUBSTRING_INDEX(
    SUBSTRING_INDEX(
      "07-Mar-2020 18:11:34.456 queries: info: client 55.44.33.22#49230 (111.222.333.444.in-addr.arpa): view All_View: query: 111.111.111.111.in-addr.arpa IN PTR + (22.22.22.22)",
      "query: ",
      -1
    ),
    " IN PTR",
    1
  ) as `request`

Result:
5e63789219175851589352.png

D
d-stream, 2020-03-07
@d-stream

That's exactly what it's better not to shove into the trigger .... in order to avoid bullet holes in the knees and holes in the soles from the rake ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question