Mysql Explain 详解
引自 http://www.itpub.net/thread-1034410-1-1.html
Mysql Explain 详解
一.语法
explain < table_name >
例如: explain select * from t3 where id=3952602;
二.explain输出解释
+----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------+
1.id
我的理解是SQL执行的顺利的标识,SQL从大到小的执行.
例如:
mysql> explain select * from (select * from ( select * from t3 where id=3952602) a) b;
+----+-------------+------------+--------+-------------------+---------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+--------+-------------------+---------+---------+------+------+-------+
| 1 | PRIMARY | <derived2> | system | NULL | NULL | NULL | NULL | 1 | |
| 2 | DERIVED | <derived3> | system | NULL | NULL | NULL | NULL | 1 | |
| 3 | DERIVED | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | | 1 | |
+----+-------------+------------+--------+-------------------+---------+---------+------+------+-------+
很显然这条SQL是从里向外的执行,就是从id=3 向上执行.
2. se
相关文档:
在FC8中默认安装的有mysql,没有的话可以很方便的安装下。
默认的mysql的include文件目录在/usr/include/mysql
默认的mysql的lib文件夹在/usr/lib/mysql
这两个目录在我们编译时候需要到。
我的测试用的C代码为:
#include <stdio.h>
#include <stdlib.h>
#include <mysql.h>
#define CONN_HOST ......
mysql> create table testdate(
-> id int not null auto_increment primary key,
-> time date);
Query OK, 0 rows affected (0.30 sec)
mysql> insert into testdate(time) values('2010-4-23');
Q ......
MYSQL 8小时 断开链接问题
解决办法有两个:第一是设置autoReconnect属性设置为true;第二是设置DBCP 时将testquery等几个属性一并设置。
问题的原因是,MySQL的参数interactive_timeout,也就是交互超时时间默认为8小时。也就是如果一个链接在8小时后,还没有和服务器交互,这个连接就会被MySQL服务器断开。因为MySQL能 ......
假如我们的mysql有一个计数器,而这个计数器需要我们重新统计,怎么办呢?
应用场景,比如说有一个商场,每卖一个产品都产生一个流水,然后我们需要知道每笔流水是该产品第几次出售的,这样说可能不明白,我拿一个详细的数据
举例吧。
recordID,productID,productType,sellDate,counter
1, 1, 1, '2010-1-15 15:20:10 ......
首先,要下载一个连接mysql数据库的驱动程序: mysql-connector-java-3.0.15-ga-bin.jar, 这个驱动程序不需要做其它配置,也就是说,对于mysql数据库,不必像access或者oracle要建立odbc数据源。
其次,将上面的.jar文件加入到classpath环境变量中。
最后,就是写代码进行测试了。
主要代码如下:
......