Mysql 服务器在 LONGBLOB 中存储大型 (2MB) 音频文件时发生故障

Mysql server has gone away while storing large (2MB) audio file in LONGBLOB

我想在 mysql 数据库中存储一个音频文件。我正在使用 LONGBLOB 来存储此音频文件的 base64 编码字符串。但是就在我执行查询时,我收到了这个没有插入数据库的警告:

Warning: mysql_query() [function.mysql-query]: MySQL server has gone away 

当我上传任何图像文件时,我没有收到任何错误并且代码工作正常。当我上传视频和音频文件时会发生这种情况。下面是我正在使用的代码:

<?php
    include 'database_handler.php';
    if(isset($_FILES['fileToUpload']['name'])){
    echo "uploading. . .";
    $file = rand(0, 10000000).$_FILES['fileToUpload']['name'];
    if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $file)) {
        if($fp = fopen($file,"rb", 0))
        {
           $picture = fread($fp,filesize($file));
           fclose($fp);
           $base64 = base64_encode($picture);
           //echo $base64;
           $db = new Database();
           $db->test($base64);
        }
    }
}
?>
<form action="test.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

这是我调用的函数代码:

function test($base64String){
    if (mysql_query("update users set attribute1='$base64String' where id = '83'")){
                    echo "success";

                }else{
                    mysql_error();
                }
}

谢谢

请增加/etc/mysql/my.cnf,

wait_timeout = 3600

max_allowed_packet = 128M

并重启

sudo /etc/init.d/mysql restart

注意:为什么要将音频文件存储在数据库中,而不是存储它的路径并将文件存储在系统中