mysql一条最简单的SQL语句,执行缺很慢,求解 SELECT * FROM tbl_name LIMIT 0 , 30 就这么一条sql语句,执行时间要超过1秒,数据差不多14万 另外一个表,数据量9万,执行同样的sql差不多0.005百思不得其解啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 表中是否有索引EXPLAIN SELECT * FROM tbl_name LIMIT 0 , 30 EXPLAIN SELECT * FROM tbl_name LIMIT 0 , 30 看看 表没有做关联的。现在我做了这样一个测试,我复制了一模一样的一张表,就是比较慢的那张表(tbl1),重命名为tbl2然后同样的sql语句在tbl2中执行,速度就快了,我在想会不会是程序问题而拖慢了tbl1因为tbl2没有程序在使用,所以就快了 执行EXPLAIN SELECT * FROM tbl1 LIMIT 0 , 30 的结果id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE tbl1 ALL NULL NULL NULL NULL 170880 没有用到索引 ,SHOW INDEX FROM TBNAME show create table tbl_name ;贴出来看一下。 CREATE TABLE `tbl1` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `gid` char(9) DEFAULT '012', `SelectU` int(11) DEFAULT NULL, `userID` int(11) NOT NULL DEFAULT '0', `houseID` text, `type_ix` smallint(2) unsigned NOT NULL DEFAULT '1', `poster` char(32) NOT NULL DEFAULT '0', `password` char(32) NOT NULL DEFAULT '0', `classify_ix` smallint(2) NOT NULL DEFAULT '0', `area` float NOT NULL DEFAULT '0', `floor` char(32) DEFAULT NULL, `contacts` varchar(100) DEFAULT NULL, `tel` varchar(64) NOT NULL DEFAULT '0', `location` char(64) NOT NULL, `city` char(30) DEFAULT NULL, `part` char(20) NOT NULL DEFAULT '0', `memo` varchar(500) DEFAULT NULL, `created` int(10) NOT NULL DEFAULT '0', `expired` int(10) NOT NULL DEFAULT '0', `ontopexpired` int(10) DEFAULT NULL, `passed` int(1) NOT NULL DEFAULT '0', `approved` int(10) NOT NULL DEFAULT '0', `plan_picture` char(128) NOT NULL DEFAULT '0', `on_top` smallint(1) NOT NULL DEFAULT '0', `userUp` tinyint(1) unsigned NOT NULL DEFAULT '0', `updated` int(10) NOT NULL DEFAULT '0', `price_unit` smallint(6) NOT NULL DEFAULT '0' COMMENT '价格单位', `price` float NOT NULL DEFAULT '0', `build_date` int(10) NOT NULL DEFAULT '0', `basic` char(100) DEFAULT NULL, `home_ea` char(100) DEFAULT NULL, `fitment` char(100) DEFAULT NULL, `real_photo` char(128) NOT NULL DEFAULT '0', `click_count` int(11) DEFAULT '0', `ip` char(15) NOT NULL DEFAULT '0', `keyword` text, `UclassID` int(11) DEFAULT NULL, `imgcode` text, `mappoint` varchar(50) DEFAULT NULL, `manualKeyword` varchar(50) DEFAULT NULL, `autoUpdate` int(1) NOT NULL DEFAULT '0', `allowComments` int(1) NOT NULL DEFAULT '1', `msgUniqueID` varchar(7) DEFAULT NULL, `agree` int(11) NOT NULL DEFAULT '0', `disagree` int(11) NOT NULL DEFAULT '0', `needclose` int(11) DEFAULT '0' COMMENT '标识需要关闭的房产信息', PRIMARY KEY (`id`), KEY `userUp` (`userUp`), KEY `userID` (`userID`,`type_ix`), KEY `type_ix` (`type_ix`,`passed`), KEY `classify_ix` (`classify_ix`,`passed`), KEY `on_top` (`on_top`,`passed`), KEY `tel` (`tel`), KEY `expired` (`expired`), KEY `updated` (`updated`), KEY `gid` (`gid`), KEY `passed` (`passed`), FULLTEXT KEY `keyword` (`keyword`)) ENGINE=MyISAM AUTO_INCREMENT=4304501 DEFAULT CHARSET=gbk 只是简单的 select * from `tbl1` limit 30 应该不会慢啊。show profiles 看一下时间都分配在什么步骤上了。再试一下 select * from `tbl1` order by id limit 30 SHOW PROCESSLIST 看一下同时有哪些进程在操作数据库。特别是锁表,会影响你的操作。 Mysql的传输安全问题 php向mysql插入语句是因为多了 ‘ 出错,求解决方法 大神们 关于导入数据库 出错 #1064 数据抽样问题 MYSQL远程连接服务器问题(急) mysql insert 中文乱码 一个库里表多了,对mysql的性能是不是很有影响 超级菜鸟问题。。 帮忙啊 Python中使用postgreSql,import出错 关于mysql的安装---一个很简单的问题 mysql分区表性能问题 update 900W记录的sql语句执行之后,卡在那里,如何优化?
EXPLAIN SELECT * FROM tbl_name LIMIT 0 , 30
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE tbl1 ALL NULL NULL NULL NULL 170880
SHOW INDEX FROM TBNAME
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`gid` char(9) DEFAULT '012',
`SelectU` int(11) DEFAULT NULL,
`userID` int(11) NOT NULL DEFAULT '0',
`houseID` text,
`type_ix` smallint(2) unsigned NOT NULL DEFAULT '1',
`poster` char(32) NOT NULL DEFAULT '0',
`password` char(32) NOT NULL DEFAULT '0',
`classify_ix` smallint(2) NOT NULL DEFAULT '0',
`area` float NOT NULL DEFAULT '0',
`floor` char(32) DEFAULT NULL,
`contacts` varchar(100) DEFAULT NULL,
`tel` varchar(64) NOT NULL DEFAULT '0',
`location` char(64) NOT NULL,
`city` char(30) DEFAULT NULL,
`part` char(20) NOT NULL DEFAULT '0',
`memo` varchar(500) DEFAULT NULL,
`created` int(10) NOT NULL DEFAULT '0',
`expired` int(10) NOT NULL DEFAULT '0',
`ontopexpired` int(10) DEFAULT NULL,
`passed` int(1) NOT NULL DEFAULT '0',
`approved` int(10) NOT NULL DEFAULT '0',
`plan_picture` char(128) NOT NULL DEFAULT '0',
`on_top` smallint(1) NOT NULL DEFAULT '0',
`userUp` tinyint(1) unsigned NOT NULL DEFAULT '0',
`updated` int(10) NOT NULL DEFAULT '0',
`price_unit` smallint(6) NOT NULL DEFAULT '0' COMMENT '价格单位',
`price` float NOT NULL DEFAULT '0',
`build_date` int(10) NOT NULL DEFAULT '0',
`basic` char(100) DEFAULT NULL,
`home_ea` char(100) DEFAULT NULL,
`fitment` char(100) DEFAULT NULL,
`real_photo` char(128) NOT NULL DEFAULT '0',
`click_count` int(11) DEFAULT '0',
`ip` char(15) NOT NULL DEFAULT '0',
`keyword` text,
`UclassID` int(11) DEFAULT NULL,
`imgcode` text,
`mappoint` varchar(50) DEFAULT NULL,
`manualKeyword` varchar(50) DEFAULT NULL,
`autoUpdate` int(1) NOT NULL DEFAULT '0',
`allowComments` int(1) NOT NULL DEFAULT '1',
`msgUniqueID` varchar(7) DEFAULT NULL,
`agree` int(11) NOT NULL DEFAULT '0',
`disagree` int(11) NOT NULL DEFAULT '0',
`needclose` int(11) DEFAULT '0' COMMENT '标识需要关闭的房产信息',
PRIMARY KEY (`id`),
KEY `userUp` (`userUp`),
KEY `userID` (`userID`,`type_ix`),
KEY `type_ix` (`type_ix`,`passed`),
KEY `classify_ix` (`classify_ix`,`passed`),
KEY `on_top` (`on_top`,`passed`),
KEY `tel` (`tel`),
KEY `expired` (`expired`),
KEY `updated` (`updated`),
KEY `gid` (`gid`),
KEY `passed` (`passed`),
FULLTEXT KEY `keyword` (`keyword`)
) ENGINE=MyISAM AUTO_INCREMENT=4304501 DEFAULT CHARSET=gbk