Recent

Author Topic: Writing text file to Mysql  (Read 1367 times)

Noobie

  • New member
  • *
  • Posts: 8
Writing text file to Mysql
« on: July 21, 2021, 09:30:04 am »
I have a mysql db where is table with five columns, like id, machine 1..3 and log where is 1 to 15 rows.
All machines have state from 0 to 3 and common log file which is updated every 60-70 seconds.

How do I write a log file to specific column like..

id | m1 | m2 | m3 | log
1     0      2       2     A1332
                               A2321
                               B4435
                               A2212

2     0       1      0     C3322
                               A2231


Thanks!


dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: Writing text file to Mysql
« Reply #1 on: July 22, 2021, 10:01:22 am »
There is a couple of ways to accomplish this.

I.) You can write log in each row like below. You probably can't have primary key in this way, or you could add 'rowno' or similar as autoincrement primary key.

Code: Text  [Select][+][-]
  1. id  | m1   | m2    | m3  | log
  2. 1     0      2       2     A1332
  3. 1     0      2       2     A2321
  4. 1     0      2       2     B4435
  5. 1     0      2       2     A2212
  6. 2     0      1       0     C3322
  7. 2     0      1       0     A2231

II.) You could write each 'id' in one separate row (as you suggested it), but 'log' column should be big enough to store maximum possible 'log' values (plus separators).

Code: Text  [Select][+][-]
  1. id  | m1   | m2    | m3  | log
  2. 1     0      2       2     A1332 <newline> A2321 <newline> B4435 <newline> A2212
  3. 2     0      1       0     C3322 <newline> A2231

III.) Add another table. In the parent table you store 'm1', 'm2' and 'm3'. In the child table you store 'log' values. Column 'id' is link between tables.

Parent table would look like this:

Code: Text  [Select][+][-]
  1. id  | m1   | m2    | m3
  2. 1     0      2       2
  3. 2     0      1       0

Child table would look like this:

Code: Text  [Select][+][-]
  1. id  | log
  2. 1     A1332
  3. 1     A2321
  4. 1     B4435
  5. 1     A2212
  6. 2     C3322
  7. 2     A2231

 

TinyPortal © 2005-2018