Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mySQL中增加较慢的数据插入_Mysql_Mysql Error 1142 - Fatal编程技术网

在mySQL中增加较慢的数据插入

在mySQL中增加较慢的数据插入,mysql,mysql-error-1142,Mysql,Mysql Error 1142,背景: >> MySQLTuner 1.1.1 - Major Hayden <major@mhtx.net> >> Bug reports, feature requests, and downloads at http://mysqltuner.com/ >> Run with '--help' for additional options and output filtering Please enter your MySQL a

背景:

 >>  MySQLTuner 1.1.1 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: xxxxx
Please enter your MySQL administrative password:xxxxx

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.85-community
[OK] Operating on 32-bit architecture with less than 2GB RAM

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 101M (Tables: 1344)
[!!] InnoDB is enabled but isn't being used
[!!] Total fragmented tables: 1

-------- Security Recommendations  -------------------------------------------
ERROR 1142 (42000) at line 1: SELECT command denied to user 'xxxx'@'localhost' for table 'user'
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 5d 15h 53m 55s (2M q [4.395 qps], 9K conn, TX: 1B, RX: 425M)
[--] Reads / Writes: 51% / 49%
[--] Total buffers: 34.0M global + 2.7M per thread (500 max threads)
[OK] Maximum possible memory usage: 1.3G (67% of installed RAM)
[OK] Slow queries: 0% (9/2M)
[OK] Highest usage of available connections: 1% (5/500)
[!!] Key buffer size / total MyISAM indexes: 8.0M/105.3M
[!!] Key buffer hit rate: 94.1% (72M cached / 4M reads)
[!!] Query cache is disabled
[OK] Temporary tables created on disk: 7% (101 on disk / 1K total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 0% (64 open / 277K opened)
[OK] Open file limit used: 0% (127/18K)
[OK] Table locks acquired immediately: 99% (2M immediate / 2M locks)
[!!] Connections aborted: 38%

-------- Recommendations -----------------------------------------------------
General recommendations:
    Add skip-innodb to MySQL configuration to disable InnoDB
    Run OPTIMIZE TABLE to defragment tables for better performance
    Enable the slow query log to troubleshoot bad queries
    Set thread_cache_size to 4 as a starting value
    Increase table_cache gradually to avoid file descriptor limits
    Your applications are not closing MySQL connections properly
Variables to adjust:
    key_buffer_size (> 105.3M)
    query_cache_size (>= 8M)
    thread_cache_size (start at 4)
    table_cache (> 64)
我们有大约60GB的大型平面文件,正在插入数据库。我们在插入过程中遇到性能降级的问题

  • 我们有174(百万)条记录,预计还会有5000(百万)条记录被插入
  • 我们已经根据实体名称的前两个字符将主表拆分为1000多个表 e、 g.实体aa、实体ab。。。实体_zz
  • 在每次插入过程中,会运行三个查询:(a)对另一个表进行基于范围的搜索,(b)检查记录是否已插入(c)插入到详细信息(实体摘要)表中
  • 我们添加了实体概要来处理频繁的搜索查询,但意识到,在插入数据库时,无论我们是否更改表实体(或实体概要)禁用(或启用)键,它都会逐渐变慢
  • 这台机器有4个CPU、千兆磁盘空间和2GB RAM。操作系统为Linux CentOS(5.4)32位
  • 我们发现并非所有4个CPU都得到了利用
  • 我们一次运行了4个导入脚本,但总体性能并不令人满意
问题表格

CREATE TABLE `entity_briefs` (
`entity_brief_id` bigint(11) NOT NULL auto_increment,
`entity_id` bigint(11) default NULL,
`entity_table_prefix` char(2) default NULL,
`string_1` varchar(255) default NULL,
`string_2` varchar(255) default NULL,
`zip` varchar(25) default NULL,
`phone` bigint(11) default NULL,
PRIMARY KEY  (`entity_brief_id`),
KEY `idx_entity_id` (`entity_id`),
KEY `idx_entity_table_prefix` (`entity_table_prefix`),
KEY `idx_zip` (`zip`),
KEY `idx_string_1` (`string_1`),
KEY `idx_string_2` (`string_2`),
KEY `idx_phone` (`phone`)
);
mysqltuner.pl输出:

 >>  MySQLTuner 1.1.1 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering
Please enter your MySQL administrative login: xxxxx
Please enter your MySQL administrative password:xxxxx

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.85-community
[OK] Operating on 32-bit architecture with less than 2GB RAM

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 101M (Tables: 1344)
[!!] InnoDB is enabled but isn't being used
[!!] Total fragmented tables: 1

-------- Security Recommendations  -------------------------------------------
ERROR 1142 (42000) at line 1: SELECT command denied to user 'xxxx'@'localhost' for table 'user'
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 5d 15h 53m 55s (2M q [4.395 qps], 9K conn, TX: 1B, RX: 425M)
[--] Reads / Writes: 51% / 49%
[--] Total buffers: 34.0M global + 2.7M per thread (500 max threads)
[OK] Maximum possible memory usage: 1.3G (67% of installed RAM)
[OK] Slow queries: 0% (9/2M)
[OK] Highest usage of available connections: 1% (5/500)
[!!] Key buffer size / total MyISAM indexes: 8.0M/105.3M
[!!] Key buffer hit rate: 94.1% (72M cached / 4M reads)
[!!] Query cache is disabled
[OK] Temporary tables created on disk: 7% (101 on disk / 1K total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 0% (64 open / 277K opened)
[OK] Open file limit used: 0% (127/18K)
[OK] Table locks acquired immediately: 99% (2M immediate / 2M locks)
[!!] Connections aborted: 38%

-------- Recommendations -----------------------------------------------------
General recommendations:
    Add skip-innodb to MySQL configuration to disable InnoDB
    Run OPTIMIZE TABLE to defragment tables for better performance
    Enable the slow query log to troubleshoot bad queries
    Set thread_cache_size to 4 as a starting value
    Increase table_cache gradually to avoid file descriptor limits
    Your applications are not closing MySQL connections properly
Variables to adjust:
    key_buffer_size (> 105.3M)
    query_cache_size (>= 8M)
    thread_cache_size (start at 4)
    table_cache (> 64)
MySQLTuner 1.1.1-海登少校 >>错误报告、功能请求和下载http://mysqltuner.com/ >>使用“--help”运行以获取其他选项和输出筛选 请输入您的MySQL管理登录名:xxxxx 请输入您的MySQL管理密码:xxxxx --------一般统计数字-------------------------------------------------- [-]跳过了MySQLTuner脚本的版本检查 [确定]当前运行受支持的MySQL 5.0.85-community版本 [正常]在32位体系结构上运行,内存小于2GB --------存储引擎统计信息------------------------------------------- [-]状态:+Archive-BDB-federed+InnoDB-ISAM-NDBCluster [--]MyISAM表格中的数据:101M(表格:1344) [!!]InnoDB已启用,但未被使用 [!!]碎片表总数:1 --------安全建议------------------------------------------- 第1行出现错误1142(42000):为表“user”选择拒绝给用户“xxxx”@“localhost”的命令 [确定]所有数据库用户都已分配密码 --------性能指标------------------------------------------------- [--]截止时间:5d 15h 53m 55s(2M q[4.395 qps],9K连接器,德克萨斯州:1B,RX:425M) [-]读/写:51%/49% [-]总缓冲区:34.0M全局+每线程2.7M(最多500个线程) [确定]最大可能内存使用量:1.3G(占已安装RAM的67%) [确定]慢速查询:0%(9/2M) [确定]可用连接的最高使用率:1%(5/500) [!!]关键缓冲区大小/MyISAM索引总数:8.0M/105.3M [!!]键缓冲区命中率:94.1%(72M缓存/4M读取) [!!]查询缓存已禁用 [确定]在磁盘上创建的临时表:7%(磁盘上101个/1K总数) [!!]线程缓存已禁用 [!!]表缓存命中率:0%(64个打开/277K个打开) [确定]使用的打开文件限制:0%(127/18K) [确定]立即获取的表锁:99%(2M立即/2M锁) [!!]连接中止:38% --------推荐----------------------------------------------------- 一般性建议: 将skip innodb添加到MySQL配置以禁用innodb 运行“优化表”对表进行碎片整理以获得更好的性能 启用慢速查询日志以排除错误查询的故障 将线程\u缓存\u大小设置为4作为起始值 逐渐增加表缓存以避免文件描述符限制 您的应用程序没有正确关闭MySQL连接 要调整的变量: 按键缓冲区大小(>105.3M) 查询缓存大小(>=8M) 线程缓存大小(从4开始) 表\u缓存(>64) 要求:
为了加快插入速度,可以使用什么样的优化策略?

一些一般性建议,因为我没有给你的灵丹妙药:

我不认为随着表大小的增长,insert的速度会降低。数据库插入时间通常会随着数据库大小的增加而增加,诀窍是在满足这一期望的情况下,尽量使总体性能可以接受

若速度变慢了,CPU并没有固定,那个么您可能在数据库访问上受到I/O限制。如果发现这种情况,您可能需要尝试更快的驱动器、RAID 0、更快的驱动器控制器等。甚至可以考虑在固态驱动器上建立数据库,然后在创建后将其复制到传统硬盘驱动器。对于mysql在文件系统上的随机访问行为来说,这应该要快得多,尽管我知道随着时间的推移,这些行为会逐渐消失。不过,你可以在1万美元以下获得1 TB的固态存储

还要仔细研究一下优化插入过程。在插入过程中禁用索引(如您所述),虽然不会停止逐渐减慢,但会显著加快整个过程。我从您的描述中了解到,您有某种插入脚本逻辑,可以进行选择和插入,而不是简单地加载平面文件。每次插入都要执行三个不同的查询,可能会在客户机和数据库之间多次往返数据。特别是查看这个范围内的select,并确保这个查询本身在表大小方面没有糟糕的性能特征


另一种可能是在这个问题上投入更多的RAM,并将其用作磁盘缓存。如果您运行这些范围选择的“其他表”在insertfest期间没有被修改,如果您确定寻道时间确实是这里的性能限制,那么您可以在内存中获得该表以减少驱动器寻道时间。

您好,感谢全面的推荐。希望我能给你10分:)