Need help with one line insert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Micke

    Need help with one line insert

    I need to do a one line insert to a MySQL database from a Linux Shell.

    I have a program that collects data and I can do a one-line shell call
    after the data-update is finished. On this line I would like to send
    the data from the program to a MySQL database.

    The problem is that the program has all data in variables so I would
    like to do something like this (postlog = after update):

    postlog "insert var1, var2, var3 into database.table"

    Can this be done in only one line shell call (program limit) or do I
    have to write a script and pass variables?

    If it can be done, how...

    /Micke
  • Bill Karwin

    #2
    Re: Need help with one line insert

    Micke wrote:
    [color=blue]
    > I have a program that collects data and I can do a one-line shell call
    > after the data-update is finished. On this line I would like to send
    > the data from the program to a MySQL database.[/color]

    You can execute SQL statements from command-line arguments to the mysql
    tool:

    mysql -u $user -p$password $database -e "INSERT INTO myTable (field1,
    field2, field3) VALUES ($var1, $var2, $var3)"

    Regards,
    Bill K.

    Comment

    • Micke

      #3
      Re: Need help with one line insert

      A million thanks Bill. It works wounderful!!!

      Regards,
      /Micke

      Bill Karwin <bill@karwin.co m> wrote in message news:<cngefp01v 2e@enews4.newsg uy.com>...[color=blue]
      > Micke wrote:
      >[color=green]
      > > I have a program that collects data and I can do a one-line shell call
      > > after the data-update is finished. On this line I would like to send
      > > the data from the program to a MySQL database.[/color]
      >
      > You can execute SQL statements from command-line arguments to the mysql
      > tool:
      >
      > mysql -u $user -p$password $database -e "INSERT INTO myTable (field1,
      > field2, field3) VALUES ($var1, $var2, $var3)"
      >
      > Regards,
      > Bill K.[/color]

      Comment

      Working...