【问题标题】:MySQL process uses more than 100% CPU usage and need about 1 GB of memoryMySQL 进程使用超过 100% 的 CPU 使用率,需要大约 1 GB 的内存
【发布时间】:2009-11-07 11:29:07
【问题描述】:

我在具有以下规格的服务器上运行 MySQL 服务器 -

双至强四核 2.0、2048 MB RAM、1 个 160 GB SATA Fedora Core + SSH

但是插入 10000 条记录的 MySQL 进程占用超过 100% 的 CPU 和高达 1 GB 的 RAM。 这是一个简单的插入语句。

为什么 MySQL 会占用如此多的内存,可以做些什么呢?

【问题讨论】:

  • 没有足够的信息来回答,可能属于 serverfault.com
  • 请发布您的架构和插入语句。
  • 抱歉抖动。如果我在错误的论坛上发帖。这些是详细信息:- 使用 Test1;插入客户(名字、姓氏、国家 ID、地址、电话)从 Test2.Customer 中选择名字、姓氏、国家 ID、地址、电话,其中 UserID 介于 1 和 5000 之间,客户 ID 在(从 Cust_Details 中选择 CustId,其中 CustName 像“Mi%”) ;
  • 肯定超过 100% 是由于多个进程/线程造成的。

标签: mysql memory process cpu uses


【解决方案1】:

查询中最重要的部分是 SELECT:

Select FirstName, LastName, CountryID, Address, Phone
From Test2.Customer
Where UserID Between 1 and 5000
and CustomerID in (Select CustId from Cust_Details Where CustName like 'Mi%')

嵌套查询可能会针对每一行重复。您可以检查这个正在运行的EXPLAIN PLAN + 所有 SELECT 查询。我猜想'like' 运算符用于非索引列。在这种情况下 (like 'xyz%'),一个简单的索引可以大大提高性能。

[补充:此外,SELECT CustId ...必须输出大于5000的id,根本不需要。 Cust_Details 上的复合索引(CustId、CustName)也必须有用。]

尝试使用连接:

Select FirstName, LastName, CountryID, Address, Phone
From Test2.Customer c, Cust_Details cd
Where c.UserID Between 1 and 5000
and c.CustomerID=cd.CustId
and left(cd.CustName) = 'Mi'

【讨论】:

    猜你喜欢
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    相关资源
    最近更新 更多