表的结构为:
mysql> desc t_role;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | NULL | |
+-------+--------------+------+-----+---------+----------------+
查询数据结果:
mysql> select * from t_role;
+----+-----------+
| id | name |
+----+-----------+
| 4 | scriptguy |
| 3 | 模块1 |
| 2 | 暖暖的 |
+----+-----------+
3 rows in set (0.00 sec)
请问这是为什么呢?
mysql> desc t_role;
+-------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | NULL | |
+-------+--------------+------+-----+---------+----------------+
查询数据结果:
mysql> select * from t_role;
+----+-----------+
| id | name |
+----+-----------+
| 4 | scriptguy |
| 3 | 模块1 |
| 2 | 暖暖的 |
+----+-----------+
3 rows in set (0.00 sec)
请问这是为什么呢?
一般看到的插入都是在最末位的位置,应该是最后一行。
查询的排序由ORDER BY控制,插入的物理位置由MYSQL控制,但楼主的控制和一般的是不一样的,估计是哪个参数配置的问题。求答案
mysql> insert into t1 values(1), (2), (3);
Query OK, 3 rows affected (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 0mysql> select * from t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.03 sec)mysql> delete from t1 where id = 2;
Query OK, 1 row affected (0.02 sec)mysql> insert into t1 values(2);
Query OK, 1 row affected (0.00 sec)mysql> select * from t1;
+------+
| id |
+------+
| 1 |
| 3 |
| 2 |
+------+
3 rows in set (0.00 sec)mysql> delete from t1 where id = 1;
Query OK, 1 row affected (0.00 sec)mysql> insert into t1 values(1);
Query OK, 1 row affected (0.00 sec)mysql> select * from t1;
+------+
| id |
+------+
| 3 |
| 2 |
| 1 |
+------+
3 rows in set (0.00 sec)mysql>
恩,现在明白了,不加order by的话mysql不保证按顺序输出结果集。
谢谢回帖