2012-08-09 137 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