Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

MySQL gone Away

by stew (Scribe)
on Oct 14, 2002 at 13:33 UTC ( [id://205067]=perlquestion: print w/replies, xml ) Need Help??

stew has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to run thru a directory of PDF's, read each one in turn into memory and then store them in MySQL

I get thru about 8 or so when I get the following error

DBD::mysql::st execute failed: MySQL server has gone away at insert_pd line 76. de140202.pdf

My query looks like this

my $sth = $dbh->prepare(q{insert into ee_pdf(id,data) values (?,?)});

I am reading the pdf like this
open(FILE,"<".$filename) || die ("Could not open FILE"); @file_arr = <FILE>; close(FILE); foreach $line(@file_arr) { $data .= $line; }

And executing the query thus..


Any idea why this might be?

Replies are listed 'Best First'.
Re: MySQL gone Away
by blokhead (Monsignor) on Oct 14, 2002 at 14:06 UTC
    I had this problem as well while putting large BLOBs into the database. The problem turned out to be that the server had set an upper limit on the amount of data sent at once. If I remember correctly, you can change this in the /etc/mysql/my.cnf file like this:
    set-variable = max_allowed_packet=256M # or something else ridiculously large


Re: MySQL gone Away
by xtype (Deacon) on Oct 14, 2002 at 14:10 UTC
    You are trying to execute a query larger than your max_allowed_packet perhaps?

    And you could be reading your file with read
    open(FILE,"<".$filename) || die ("Could not open FILE"); my $size = -s $fname; my $data; read FILE, $data, $size; $sth->execute($pid, $_, $data, $public) if $data; close(FILE);
    After checking and possibly adjusting your max_allowed_packets (else if you cannot adjust it) you could do something along the lines of this: Handling huge BLOB fields with DBI and MySQL

Re: MySQL gone Away
by diotalevi (Canon) on Oct 14, 2002 at 13:58 UTC

    From grepping mysql source it's just a db connection issue. I'd guess you just abended the server-side mysql process somehow and the client noticed the disconnection. Consider looking into your MySQL documentation further to see how you're breaking MySQL. Perhaps your data column cannot accept binary data. Perhaps you need to use a different interface to get your data loaded into the db.

    Update: Hmm... apparently I was incorrect. Oh well.

    __SIG__ printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B:: +svref_2object(sub{})->OUTSIDE
Re: MySQL gone Away
by bronto (Priest) on Oct 14, 2002 at 16:43 UTC

    Since you already had your MySQL replies, I'll concentrate on your Perl :-)

    Without loss of readability, you could compact your code in:

    open(FILE,"<".$filename) || die ("Could not open FILE"); $data .= $_ foreach <FILE> ; # for example close(FILE);


    # Another Perl edition of a song:
    # The End, by The Beatles
    END {
      $you->take($love) eq $you->make($love) ;

      Why iterate, when you can get the whole file in one big slurp?
      { local $/ = undef; open(FILE,"<".$filename) || die ("Could not open: $!"); $data = <FILE>; close(FILE); }

      OmG! They killed tilly! You *bleep*!!

        Only for the sake of KISS, nothing more and nothing less.


        # Another Perl edition of a song:
        # The End, by The Beatles
        END {
          $you->take($love) eq $you->make($love) ;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://205067]
Approved by IlyaM
Front-paged by tye
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-18 00:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found