MySQL Forums
Forum List  »  Newbie

How to change max_allowed_packet size?
Posted by: Yu-Hwei Chou
Date: December 21, 2009 02:09PM

Hi everyone,
I don't know if this is what is causing my "MySQL Server has Gone away" warning, but it was one of the suggestions on this site to try to fix. However this website references something called "mysqld" on which one can give commands like "--verbose --help." I don't seem to have this client installed but I have an exe by the name mysqld. Anyway so I can't use their instructions that involve mysqld.

Everytime I run SHOW VARIABLES on mysql command client, my variable max_allowed_packet is always 1048576. I've gone in to all the ini's and changed it to 16M and I've also tried the command SET but it always remains the same. What am I doing wrong?

Also to zoom out a little, I'm trying to insert a blob that is 8Mb large into my database into a long blob column. Here is the function I use to upload it:

<?php
// the upload function
function upload(){
$maxsize=10000000;
$file_info = new finfo(FILEINFO_MIME_TYPE); // object oriented approach!
$tmpname = $_FILES['userfile']['tmp_name']['0'];

$mime_type = $file_info->buffer(file_get_contents($tmpname)); //


if(is_uploaded_file($tmpname)) {

// check the file is less than the maximum file size
if($_FILES['userfile']['size']['0'] < $maxsize && $mime_type=='audio/mpeg')
{
// prepare the image for insertion
$imgData=mysql_real_escape_string(file_get_contents($tmpname),mysql_connect(null,'user','password'));

// get the image info..
$size = $_FILES['userfile']['size']['0'];

// put the image in the db...
// database connection
mysql_connect(NULL, 'user', 'password') OR DIE (mysql_error());

// select the db
mysql_select_db ("music_db") OR DIE ("Unable to select db".mysql_error());

// our sql query
$sql = "INSERT INTO musicfiles
( musicFile, fileSize, songName)
VALUES
( '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}')";

// insert the image
if(!mysql_query($sql)) {
echo 'Unable to upload file';
}
}

else {
// if the file is not less than the maximum allowed, print an error
echo
'<div>File exceeds the Maximum File limit or is not in MP3 format</div>
<div>Maximum File limit is '.$maxsize.'</div>
<div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile'['size']['0'].' bytes</div>
<div>File Type of '.$_FILES['userfile']['name']['0'].' is '.$mime_type.' </div>
<div>'.($mime_type==='audio/mpeg').'</div>
<hr />';
}
}
else {
//if no file is uploaded
echo '<div>No file uploaded</div>';
}
}
?>

Thanks for the help.

Options: ReplyQuote


Subject
Written By
Posted
How to change max_allowed_packet size?
December 21, 2009 02:09PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.