Gossamer Forum
Home : General : Perl Programming :

MySQL server has gone away

(Page 1 of 2)
> >
Quote Reply
MySQL server has gone away
Ugh this is really annoying me.

This code keeps giving the error "MySQL server has gone away"

I have very similar code in other parts of the script that work fine but this doesn't for some reason:


Removed


Any ideas are mucho appreciato

Last edited by:

RedRum: Sep 29, 2001, 7:50 AM
Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
Ok I added a print statement in the } else { and it printed so it seems to be dying at:

$db->query_nr("INSERT INTO Members (Last_Sent) VALUES('$time')");

I don't see a problem with the query.......hmmm
Post deleted by RedRum In reply to
Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
Paul

It's because you set a SQL query, but you're not preparing it, and you're not executing it so you can not expect anything to happen.

$sth = $db->prepare($your_sql_statement);
$sth->execute;

Cheers

- wil
Quote Reply
Re: [Wil] MySQL server has gone away In reply to
Yes I am Wil - it is done inside the module Tongue

Im not that dense
Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
I am just offering my assistance, which is what you asked for, Paul.

Isn't that a slow way of retrieving data, if the perl program has to dip into a module to get an execute statment?

Cheers

- wil
Quote Reply
Re: [Wil] MySQL server has gone away In reply to
I know you are offering your assistance - all I said was it was done inside the module......no biggie.

Using a module requires one lot of query code instead of using the same code over and over whenever you need it. Links SQL uses a similar method Laugh

...so infact it's probably faster.

Last edited by:

RedRum: Sep 29, 2001, 8:03 AM
Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
It's probably faster Perl wise, becasue you do actually reduce the file size of the script. But if the script is only small anyway, and you're using modules, it's probably going to slow things down. I wonder what the cut off point is. I guess that's server dependant.

Cheers

- wil
Quote Reply
Re: [Wil] MySQL server has gone away In reply to
Possibly

My script is getting quite large and complicated so I think I'm using the best method (about 50k gzipped)

Anyway back to the error......I've deleted a chunk of code am am going to re-write it. I just don't get it though because I have almost identical code elsewhere that works....grrr
Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
you might try quoting the $time variable before inserting:

$time_Q = $dbh->quote($time);

and

INSERT INTO Members (Last_Sent) VALUES ($time_Q)

Quote Reply
Re: [RandomMouse] MySQL server has gone away In reply to
If that was the problem wouldn't it tell me there was a syntax error rather than mysql server has gone away?


Last edited by:

RedRum: Sep 29, 2001, 10:13 AM
Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
Hi,

That error is one of the most annoying ones with MySQL. It usually means something wrong on the MySQL level. Check your tables with myisamchk. Try dumping your tables to file, dropping the database, and putting them back in. Other culprits are: disk full, mysql was restarted during your connection (especially likely under mod_perl), tmp partition full, and possibly a few others.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] MySQL server has gone away In reply to
Thanks Alex.

This is what I see:

Checking MyISAM file: /home/mysql/wo_demo/Members.MYI
Data records: 4 Deleted blocks: 0
myisamchk: warning: 1 clients is using or hasn't closed the table properly
- check file-size
- check key delete-chain
- check record delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check record links
MyISAM-table '/home/mysql/wo_demo/Members.MYI' is usable but should be fixed

If the table is not closed does that mean there is something wrong in my code or could it just be an open connection?
Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
Try `myisamchk -e -f *.MYI` in your database directory. That will fix any tables.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] MySQL server has gone away In reply to
Am I safe to delete all the files from /tmp ?

There are just hundreds of files like:

php7VR86C
phpFNHBBN
phpNJRVzQ
phpUQ5jGY
Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
Not sure what they are.. =) Looks like something related to php? Perhaps session/cache files?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] MySQL server has gone away In reply to
:(

I fixed the tables, emptied the tmp directory, there are several hundred MB free in the OS partition and I still get the error ;(

The following works fine.......

my (@data) = $db->query("SELECT Last_Sent FROM Members WHERE Username='$user'");


....but as soon as I add:

Code:
if ($data[0]) {
print $in->header;
print 'ok';
}
else {
my $time = time();
$db->query_nr("UPDATE Members SET Last_Sent='$time' WHERE Username='$user'");
print $in->header;
print 'done';
}

...(just testing code)....the error appears :(

If you have the urge to take a look at how it happens you can just go here:

http://demo.wiredon.net/safe/list.cgi

....and login using Paul/willow then submit the form.

Thanks.
Quote Reply
Re: [Alex] MySQL server has gone away In reply to
Ok it isn't a server issue as I get the same error on my local pc.

Must be my code but I can't figure it out as some queries work but others give the error.

For example the signup page uses INSERT and that works - there is also a SELECT that works

:(
Quote Reply
Re: [Alex] MySQL server has gone away In reply to
From MySQL.com ->

The symptoms of a corrupted table include queries that abort unexpectedly and observable errors such as these:

Got error ### from table handler

I keep getting that error running the query from the MySQL Monitor.

ERROR 1030: Got error 127 from table handler

Must still be a problem somewhere. I'll drop the database and re-create it.
Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
127 = Record-file is crashed

Quote Reply
Re: [RedRum] MySQL server has gone away In reply to
Did you run myisamchk -e -f on all your tables? Shut down mysql first, then run it, then start mysql back up.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] MySQL server has gone away In reply to
Yep I shut it down with /etc/rc.d/init.d/mysql stop, then cd'd to the database directory, ran the repair then started it up again - still the same error.
Quote Reply
Re: [Alex] MySQL server has gone away In reply to
EDIT: Sorry ignore this post.

Last edited by:

RedRum: Sep 29, 2001, 11:17 AM
Quote Reply
Re: [Alex] MySQL server has gone away In reply to
Quote:
php7VR86C
phpFNHBBN
phpNJRVzQ
phpUQ5jGY

I am not sure how PHP stores the session files in much detail, but they do use a 32 character long string when passed along with the client, so I would assume they are stored using that string as the filename, so I wouldn't delete them on the assumption they are session files... I would delete them on the fact they are probably useless though Smile
Cheers,
Michael Bray
Quote Reply
Re: [Michael_Bray] MySQL server has gone away In reply to
sess_1222967b012d305e696ff86de135719b
that is a php session file Wink

those other ones? no clue... but since it's in /tmp and by the looks of the filename, i suppose it's semi okay to assume it's of not too much importance hehe

Adrian
> >