MySQL paging solution-create test table createtabletest (idint (11) primarykeyauto_increment, namevarchar (20) notnull); -- insert data mysqlinsertintotest (name) values (test1 ); queryOK, 1 rowaffected (0.16sec) mysqli
Environment MySQL 5.1 command line tool problem MySQL paging solution -- create test table create table test (id int (11) primary key auto_increment, name varchar (20) not null ); -- insert data mysql insert into test (name) values ('test1'); Query OK, 1 row affected (0.16 sec) mysql I
Environment
MySQL 5.1 + command line tool
Problem
MySQL Paging
Solution
-- Create test table create table test (id int (11) primary key auto_increment, name varchar (20) not null); -- insert data mysql> insert into test (name) values ('test1'); Query OK, 1 row affected (0.16 sec) mysql> insert into test (name) values ('test2'); Query OK, 1 row affected (0.01 sec) mysql> insert into test (name) values ('test3'); Query OK, 1 row affected (0.00 sec) mysql> insert into test (name) values ('test4'); Query OK, 1 row affected (0.00 sec) mysql> insert into test (name) values ('test5'); Query OK, 1 row affected (0.03 sec) mysql> insert into test (name) values ('test6'); Query OK, 1 row affected (0.01 sec) mysql> insert into test (name) values ('test7'); Query OK, 1 row affected (0.06 sec) mysql> insert into test (name) values ('test8'); Query OK, 1 row affected (0.00 sec) mysql> insert into test (name) values ('test9'); Query OK, 1 row affected (0.01 sec) mysql> insert into test (name) values ('test10'); Query OK, 1 row affected (0.01 sec) -- execute paging mysql> select id, name from test limit; + ---- + -------- + | id | name | + ---- + -------- + | 1 | test1 | 2 | test2 | 3 | test3 | 4 | test4 | 5 | test5 | | 6 | test6 | 7 | test7 | 8 | test8 | 9 | test9 | 10 | test10 | + ---- + -------- + 10 rows in set (0.00 sec)
Running Effect
Tips
Fast data insertion:
Insert into test (name) select name from test;
For details, refer to this article: How to quickly copy data tables in MySQL
Http://blog.csdn.net/btbdylq/article/details/6827981
Summary syntax
Select id, name from test limit parameter 1, parameter 2;
Parameter 1, starting from the nth
Parameter 2: How many data records are returned
Implement paging algorithm in Java Web
Select * from tableName limit (pageNow-1) * pagesize, pagesize
PageNow: Current page
PageSize: number of records displayed per page
References
Http://zhidao.baidu.com/question/248872252.html
Http://zhidao.baidu.com/question/159608774.html