目前我已经构建了一个 PHP 脚本来将一个大型数据集导入到 Innodb 表中。该脚本从文件中读取记录,构建多个查询(数据高度相关)并将它们插入数据库。我在一个新的 debian VM 上创建了这个脚本,该 VM 由一个内核和 2GB 内存构建。
需要明确的是,新鲜的意思是它是一个干净的图像,只安装了包 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