2012-08-09 132 views
-2

目前我已经构建了一个PHP脚本来将大型数据集导入到Innodb表中。 该脚本从文件读取记录,构建多个查询(数据高度关联)并将其插入数据库。我在一个新的用一个内核和2GB内存构建的debian虚拟机上创建了这个脚本。PHP-MYSQL-Innodb缓慢插入

要清楚,新鲜我的意思是这是一个干净的图像,只有包mysql-server mysql-client和php5安装。

在数据文件的虚拟机2(每个60MB +)中运行脚本时,在8秒钟内完成超过5,000条记录。

然后我将这个脚本移到了当前存放数据的服务器上,并且将保存数据库。该服务器拥有28GB RAM和2个XEON(6核)处理器。这也是全新安装,默认安装了mysql-client,mysql-server和php5-cli。清楚的是,当脚本开始并且服务器没有运行除SSH和标准系统进程以外的其他进程时,数据库为空。

在此服务器上运行脚本时,其移动速度非常慢(30秒,仅插入180条记录)。

我试过在my.cnf文件中跳过名字解析,但它似乎什么都不做。当脚本运行时,如果我在mysql中查看进程列表,我会在“释放项目”状态中不断查看插入查询。任何关于什么可能导致经济放缓的想法?

这里是服务器的问题给予::

[client] 

port   = 3306 
socket   = /var/run/mysqld/mysqld.sock 

[mysqld] 
# 
# * Basic Settings 
# 
user   = mysql 
pid-file  = /var/run/mysqld/mysqld.pid 
socket   = /var/run/mysqld/mysqld.sock 
port   = 3306 
basedir   = /usr 
datadir   = /var/lib/mysql 
tmpdir   = /tmp 
language  = /usr/share/mysql/english 
skip-external-locking 
skip-name-resolve 
# 
# Instead of skip-networking the default is now to listen only on 
# localhost which is more compatible and is not less secure. 
bind-address   = 127.0.0.1 
# 
# * Fine Tuning 
# 
key_buffer    = 16M 
max_allowed_packet  = 16M 
thread_stack   = 192K 
thread_cache_size  = 8 
# This replaces the startup script and checks MyISAM tables if needed 
# the first time they are touched 
myisam-recover   = BACKUP 
#max_connections  = 100 
#table_cache   = 64 
#thread_concurrency  = 10 
# 
# * Query Cache Configuration 
# 
query_cache_limit  = 1M 
query_cache_size  = 16M 
# 
# * Logging and Replication 
# 
# Both location gets rotated by the cronjob. 
# Be aware that this log type is a performance killer. 
# As of 5.1 you can enable the log at runtime! 
#general_log_file  = /var/log/mysql/mysql.log 
#general_log    = 1 
# 
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf. 
# 
# Here you can see queries with especially long duration 
#log_slow_queries  = /var/log/mysql/mysql-slow.log 
#long_query_time = 2 
#log-queries-not-using-indexes 
# 
# The following can be used as easy to replay backup logs or for replication. 
# note: if you are setting up a replication slave, see README.Debian about 
#  other settings you may need to change. 
#server-id    = 1 
#log_bin      = /var/log/mysql/mysql-bin.log 
expire_logs_days  = 10 
max_binlog_size   = 100M 
#binlog_do_db   = include_database_name 
#binlog_ignore_db  = include_database_name 
+0

如果您需要准确答案,您可能需要提供更多信息。这个问题可能与你的mysql配置文件... – Jocelyn 2012-08-09 21:34:53

+0

它可能是任何数量的东西。还有什么在服务器上运行?什么是网络流量?公羊使用?哪些cron作业正在运行?数据库中有多少行?你的数据库模式是什么?等等等...请尝试本地化你的问题,并提出具体的问题。我们无法登录到您的服务器并为您解决问题。 – cegfault 2012-08-09 23:29:25

+0

显示准备并将SQL插入到db的代码 – itsols 2012-08-10 01:01:29

回答

0

所以我想通了这个问题上my.cnf中。在开发服务器上,数据库最初是MyISAM,但在开发期间转换为Innodb。这导致事务和自动提交被禁用。

当移动到新服务器时,数据库从一开始就被创建为Innodb,使事务和自动提交处于活动状态。

这会导致MySQL在每次查询后都会自动提交,导致严重的减速。

的修复则是添加了查询,

Start transaction 

加载的每个文件,然后提交随即之前。

性能现在超过虚拟机。

+0

然后您可以将自己的答案标记为已接受。 – Jocelyn 2012-08-10 14:25:34