mysqldump, entire table in one insert, but multiple lines, how?

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

    mysqldump, entire table in one insert, but multiple lines, how?

    I'm aware of the recent mysqldump change, in that it now by default
    enables some optimizations.
    One of those optimizations is to use single insert statements, instead
    of separate insert statements, each on their own lines.
    I'm also aware of the --skip-opt / -e / --skip-extended-insert

    But what I'd like is a combination of having a single insert statement,
    but with each record in its own line, like so:

    INSERT INTO `article` (`id`, `title`, `text`) VALUES
    (1, 'test', 'this is a test'),
    (2, 'test2', 'also a test');

    --skip-opt or --skip-extended-insert isn't it, because that'll give me:

    INSERT INTO `article` (`id`, `title`, `text`) VALUES (1, 'test', 'this
    is a test');
    INSERT INTO `article` (`id`, `title`, `text`) VALUES (2, 'test2', 'also
    a test');

    If this can't be done with mysqldump, does anyone know of an
    alternative command-line runnable utility? Thanks in advance!

  • Bill Karwin

    #2
    Re: mysqldump, entire table in one insert, but multiple lines, how?

    HomerCritic wrote:[color=blue]
    > But what I'd like is a combination of having a single insert statement,
    > but with each record in its own line, like so:
    >
    > INSERT INTO `article` (`id`, `title`, `text`) VALUES
    > (1, 'test', 'this is a test'),
    > (2, 'test2', 'also a test');[/color]

    I also found this was useful, so I piped the output of mysqldump to a
    perl command to insert the line breaks. E.g.:

    mysqldump <options> | perl -pe 's/\),\(/),\n(/og'

    Regards,
    Bill K.

    Comment

    • HomerCritic

      #3
      Re: mysqldump, entire table in one insert, but multiple lines, how?


      Bill Karwin wrote:[color=blue]
      > HomerCritic wrote:[color=green]
      > > But what I'd like is a combination of having a single insert statement,
      > > but with each record in its own line, like so:
      > >
      > > INSERT INTO `article` (`id`, `title`, `text`) VALUES
      > > (1, 'test', 'this is a test'),
      > > (2, 'test2', 'also a test');[/color]
      >
      > I also found this was useful, so I piped the output of mysqldump to a
      > perl command to insert the line breaks. E.g.:
      >
      > mysqldump <options> | perl -pe 's/\),\(/),\n(/og'
      >[/color]

      Thanks for the feedback. I was hoping that mysqldump could do this
      built in, but piping to a script is ok I guess. Your script works,
      except if one of the strings contains a ),( it would break it.
      Is is possible to enhance the script to detect if it's inside a string?

      -Mike-

      Comment

      Working...