PHP-MYSQL-Innodb插入缓慢

时间:2012-08-09 21:08:46

标签: php mysql innodb

目前我已经构建了一个PHP脚本来将大型数据集导入Innodb表。 此脚本从文件中读取记录,构建多个查询(数据是高度相关的)并将它们插入到数据库中。我在一个使用一个内核和2GB内存构建的新的debian VM上创建了这个脚本。

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

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

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

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

我在my.cnf文件中尝试过skip-name-resolve,但似乎什么也没做。如果我在mysql中查看进程列表时脚本正在运行,我会在“释放项目”状态下看到插入查询。关于什么可能导致经济放缓的任何想法?

这是服务器上的my.cnf给出问题::

[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

1 个答案:

答案 0 :(得分:0)

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

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

这导致MySQL在每次查询后自动提交,导致速度急剧下降。

然后修复是添加查询

Start transaction

在加载每个文件然后立即提交之前。

性能现在超过VM。