以下是我的脚本,它遍历了380个MySQL InnoDB数据库并运行各种创建表格、插入、更新等操作以迁移模式。它从连接到云数据库服务器的Web服务器运行。我将迁移脚本排除在本问题之外,因为我认为这与问题无关。
我遇到了一个问题,正在尝试找到解决方法。
我有一个运行MySQL 5.6的4GB RAM云数据库服务器。我将380个具有40个表格的数据库迁移到了59个表格。在进行到70%左右时,我遇到了以下错误。它在一次迁移中间就停止了,服务器崩溃了。我观察了内存使用情况,发现它耗尽了内存。它是作为数据库服务运行的,所以我没有对服务器进行根访问,因此我不知道所有的细节。
在phppoint_smg上运行查询
Warning: Using a password on the command line interface can be insecure.
ERROR 2013 (HY000) at line 355: Lost connection to MySQL server during query
在 phppoint_soulofhalloween 数据库上运行查询
Warning: Using a password on the command line interface can be insecure.
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
在phppoint_srvais上运行查询
Warning: Using a password on the command line interface can be insecure.
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
这是 PHP 脚本的简化版本。
db_host = escapeshellarg($db_host);
$db_user = escapeshellarg($db_user);
$db_password = escapeshellarg($db_password);
foreach($databases as $database)
{
echo "Running queries on $database\n***********************************\n";
system("mysql --host=$db_host --user=$db_user --password=$db_password --port=3306 $database < ../update.sql");
echo "\n\n";
}
我的问题:
在进行迁移时,有没有办法避免内存使用量增加?我一个数据库一个数据库地进行迁移。或者是表和数据的增加导致了内存使用量增加吗?
迁移后我能够使用服务器,并删除了80个数据库并完成了迁移。它有800mb的空闲空间;我预计它会下降到600mb。 在迁移之前,它是500mb。
SHOW VARIABLES LIKE "%buffer%";
也许你配置MySQL的方式不太好。 - Rick James