MySQL支持的兩種主要表存儲格式MyISAM
測試環境
測試程序
測試方案
AutoCommit=
測試方法為插入
CREATE TABLE `MyISAM_NT` (
`TableId` int(
`TableString` varchar(
) ENGINE=MyISAM;
CREATE TABLE `MyISAM_TS` (
`TableId` int(
`TableString` varchar(
) ENGINE=MyISAM;
CREATE TABLE `INNODB_NA_NB` (
`TableId` int(
`TableString` varchar(
) ENGINE=InnoDB;
CREATE TABLE `INNODB_NA_BE` (
`TableId` int(
`TableString` varchar(
) ENGINE=InnoDB;
CREATE TABLE `INNODB_AU_NB` (
`TableId` int(
`TableString` varchar(
) ENGINE=InnoDB;
CREATE TABLE `INNODB_AU_BE` (
`TableId` int(
`TableString` varchar(
) ENGINE=InnoDB;
測試的Python腳本如下
#!/usr/bin/env Python
MyISAM
作者
時間
import MySQLdb
import sys
import os
import string
import time
c = None
testtables = [(
(
(
(
(
(
]
def BeginTrans():
c
return
def Commit():
c
return
def AutoCommit(flag):
c
return
def getcount(table):
c
return c
def AddTable (Table
sql =
try:
c
except MySQLdb
return
return c
def main():
argv = sys
if len(argv) <
sys
global c #mysql訪問cursor
db_host =
db_name =
db_user =
db_user_passwd =
if len(argv) >
tableid = argv[
testcount = int(argv[
for test in testtables:
#每次操作前都重寫建立數據庫連接
try:
mdb = nnect(db_host
except MySQLDb
sys
else:
c = mdb
table
starttime = time
print table
if autocommit != None:
AutoCommit(autocommit)
if trans ==
BeginTrans()
for i in xrange(testcount):
tablestring =
if (AddTable(table
if trans ==
Commit()
print time
endtime = time
usedtime = endtime
print table
c
mdb
if __name__ ==
main()
測試結果如下
Config:[localhost root/ demo] DB
MyISAM_NT
MyISAM_NT count:
MyISAM_TS
ExecSQL:BEGIN;
ExecSQL:COMMIT;
MyISAM_TS count:
INNODB_NA_NB
ExecSQL:Set AUTOCOMMIT =
INNODB_NA_NB count:
INNODB_NA_BE
ExecSQL:Set AUTOCOMMIT =
ExecSQL:BEGIN;
ExecSQL:COMMIT;
INNODB_NA_BE count:
INNODB_AU_NB
ExecSQL:Set AUTOCOMMIT =
INNODB_AU_NB count:
INNODB_AU_BE
ExecSQL:Set AUTOCOMMIT =
ExecSQL:BEGIN;
ExecSQL:COMMIT;
INNODB_AU_BE count:
結論
由此得知影響速度的主要原因是AUTOCOMMIT默認設置是打開的
From:http://tw.wingwit.com/Article/program/MySQL/201311/29332.html