title: Can MySQL output the equivalent of a perl packed integer?
body: <p>I'm trying to pull data from a column in MySQL table directly into a binary file which is a series of packed unsigned integers (4 bytes each) which can be read using the perl unpack function. A silly example of how I might read this data is</p>
  
  <pre><code>#!/usr/bin/env perl
  my $input_file = 'packed_int_test_file_04';
  open my $fh, '&lt;:raw', $input_file
    or die "Couldn't open $input_file for binary read: $!";
  
  my $position = 0;
  my $four_byte_buffer;
  while ( read($fh, $four_byte_buffer, 4) ) {
      my $foo_val  = unpack("I", $four_byte_buffer);
      print("Foo val at position $position is $foo_val \n");
      $position++;
  }
  
  # OUTPUT:
  # Foo val at position 0 is 1 
  # Foo val at position 1 is 2 
  # Foo val at position 2 is 3 
  # Foo val at position 3 is 4 
  # Foo val at position 4 is 5 
  # Foo val at position 5 is 6 
  </code></pre>
  
  <p>I'm hoping I can generate the data file directly from MySQL with something like the following (but I'm having no luck)</p>
  
  <pre><code>select (cast foo_val_integer as binary(4)) 
  from bar_table
  into outfile 'packed_int_test_file_04'
  FIELDS terminated by ''
  LINES terminated by '';
  </code></pre>
  
  <p>Is there a way to have MySQL directly output a sequence of 4 byte packed unsigned integers into a binary file which could be read by perl in this way?</p>