【问题标题】:frequent automatic restart of mysql server and later permanent shutdown [closed]mysql服务器频繁自动重启,后来永久关闭[关闭]
【发布时间】:2014-01-15 05:04:35
【问题描述】:

MySQL 服务器频繁重启。在不到 24 小时内完成 75 次。最后没有重启就结束了!

请在此处查看详细日志:mysqld.log

140113 10:18:22 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

140113 10:18:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140113 10:18:31  InnoDB: Initializing buffer pool, size = 8.0M
140113 10:18:31  InnoDB: Completed initialization of buffer pool
140113 10:18:31  InnoDB: Started; log sequence number 16 1064411530
140113 10:18:32 [Note] Event Scheduler: Loaded 0 events
140113 10:18:32 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.61'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution

140113 18:45:09 mysqld_safe Number of processes running now: 0
140113 18:45:10 mysqld_safe mysqld restarted
140113 18:45:10  InnoDB: Initializing buffer pool, size = 8.0M
140113 18:45:10  InnoDB: Completed initialization of buffer pool
140113 18:45:10  InnoDB: Started; log sequence number 16 1064411530
140113 18:45:11 [Note] Event Scheduler: Loaded 0 events
140113 18:45:11 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.61'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution

......

140114  9:50:12  InnoDB: Initializing buffer pool, size = 8.0M
140114  9:50:12  InnoDB: Completed initialization of buffer pool
140114  9:50:12  InnoDB: Started; log sequence number 16 1064411530
140114  9:50:13 [Note] Event Scheduler: Loaded 0 events
140114  9:50:13 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.61'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution

140114 09:55:07 mysqld_safe Number of processes running now: 0
140114 09:55:07 mysqld_safe mysqld restarted
140114  9:55:08  InnoDB: Initializing buffer pool, size = 8.0M
140114  9:55:08  InnoDB: Completed initialization of buffer pool
140114 09:55:08 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

同时,由于内存不足,它杀死了 62 个进程。请查看详细日志:messages

Jan 14 09:41:53 centos63 kernel: Out of memory: Kill process 16795 (mysqld) score 20 or sacrifice child
Jan 14 09:41:53 centos63 kernel: Killed process 16795, UID 27, (mysqld) total-vm:574508kB, anon-rss:20488kB, file-rss:164kB

我每 5 分钟运行一次 cronjob,这会影响一些表,其中三个表中有大约 200000、50000、25000 个数据。 选择超过 1,257 个成员,然后选择超过 9,844 个成员板,然后使用以下伪代码插入/更新超过 168,624 个成员卡:

<?php
    $qry = _("SELECT _members");
    while($member = mysql_fetch_assoc($res))
    {//1,257
        $qry = _("SELECT _member_boards");
        while($db_board = mysql_fetch_assoc($board_res))
        {//9,844
            $s_lists = curl_download("https://api.com/boards/lists");
            foreach ($lists as $list) {//9,844
                if(!strcmp('SOMETHING', $list->name)){//Matching with API and DB
                    $curl = "https://api.com/lists/cards";
                    foreach ($cards as $card) {//168,624
                        $qry = _("SELECT _member_cards");
                        if($card_row = mysql_fetch_assoc($card_res)){
                            $qry = _("UPDATE _member_cards");
                        }
                        else{
                            echo $qry = _("INSERT _member_cards");
                        }
                    }
                }
            }

        }
        $qry = _("UPDATE _member_cards");
    }
?>

那么可能是什么原因,我该如何解决这个问题?

到目前为止 RAM 为 512 MB。

CentOS

将 RAM 扩展到 1 GB 可以解决这个问题吗?

【问题讨论】:

  • 是的,它只是由于OOM 杀手而停止。 (1)为mysql在其配置中的使用定义合理的最大值,您可以计算它需要多少(2)将其他进程(即:您的cron作业)限制为合理的最大值(3)如果您仍然耗尽内存,添加交换(慢)或真实内存(更快但可能更昂贵)。

标签: php mysql cron


【解决方案1】:

您的 MySQL 服务器因使用过多内存而被终止;您可以向服务器添加更多 RAM 或尝试通过更改其配置文件中的某些值来降低 MySQL 的内存使用量;但是这可能会影响性能。

查看question 和this one 以获取有关调整 MySQL 配置的指南 - 这不是一件容易的事,它基于反复试验,您应该尝试不同的值,直到您在性能和内存之间取得良好的平衡用法。

【讨论】:

    猜你喜欢
    • 2020-08-22
    • 2013-11-15
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 2015-08-15
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多