Ò»¡¢Ê²Ã´ÊÇË÷Òý£¿
Ë÷ÒýÓÃÀ´¿ìËÙµØÑ°ÕÒÄÇЩ¾ßÓÐÌØ¶¨ÖµµÄ¼Ç¼£¬ËùÓÐMySQLË÷Òý¶¼ÒÔB-Ê÷µÄÐÎʽ±£´æ¡£Èç¹ûûÓÐË÷Òý£¬Ö´ÐвéѯʱMySQL±ØÐë´ÓµÚÒ»¸ö¼Ç¼¿ªÊ¼É¨ÃèÕû¸ö±íµÄËùÓмǼ£¬Ö±ÖÁÕÒµ½·ûºÏÒªÇóµÄ¼Ç¼¡£±íÀïÃæµÄ¼Ç¼ÊýÁ¿Ô½¶à£¬Õâ¸ö²Ù×÷µÄ´ú¼Û¾ÍÔ½¸ß¡£Èç¹û×÷ΪËÑË÷Ìõ¼þµÄÁÐÉÏÒѾ´´½¨ÁËË÷Òý£¬MySQLÎÞÐèɨÃèÈκμǼ¼´¿ÉѸËٵõ½Ä¿±ê¼Ç¼ËùÔÚµÄλÖá£Èç¹û±íÓÐ1000¸ö¼Ç¼£¬Í¨¹ýË÷Òý²éÕҼǼÖÁÉÙÒª±È˳ÐòɨÃè¼Ç¼¿ì100±¶¡£
¼ÙÉèÎÒÃÇ´´½¨ÁËÒ»¸öÃûΪpeopleµÄ±í£º
CREATE TABLE people ( peopleid SMALLINT NOT NULL, name CHAR(50) NOT NULL );
È»ºó£¬ÎÒÃÇÍêÈ«Ëæ»ú°Ñ1000¸ö²»Í¬nameÖµ²åÈëµ½people±í¡£ÏÂͼÏÔʾÁËpeople±íËùÔÚÊý¾ÝÎļþµÄһС²¿·Ö£º
¿ÉÒÔ¿´µ½£¬ÔÚÊý¾ÝÎļþÖÐnameÁÐûÓÐÈκÎÃ÷È·µÄ´ÎÐò¡£Èç¹ûÎÒÃÇ´´½¨ÁËnameÁеÄË÷Òý£¬MySQL½«ÔÚË÷ÒýÖÐÅÅÐònameÁУº
¶ÔÓÚË÷ÒýÖеÄÿһÏMySQLÔÚÄÚ²¿ÎªËü±£´æÒ»¸öÊý¾ÝÎļþÖÐʵ¼Ê¼Ç¼ËùÔÚλÖõēָÕ딡£Òò´Ë£¬Èç¹ûÎÒÃÇÒª²éÕÒnameµÈÓÚ“Mike”¼Ç¼µÄpeopleid£¨SQLÃüÁîΪ“SELECT peopleid from people WHERE name=\'Mike\';”£©£¬MySQLÄܹ»ÔÚnameµÄË÷ÒýÖвéÕÒ“Mike”Öµ£¬È»ºóÖ±½Óתµ ......
import java.sql.*;
import javax.resource.cci.ResultSet;
public class Temp{
public static void main(String[] args)throws Exception{
/*Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/test?user=root&password=hugh&useUnicode=true&characterEncoding=utf-8";*/
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/test?user=root&password=hugh";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from student";
java.sql.ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {
System.out.println("µÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º"+rs.getString(1));
System.out.println("µÚÒ»¸ö×Ö¶ÎÄÚÈÝΪ£º"+rs.getString(2));
}
System.out.print("Êý¾Ý¿â²Ù×÷³É¹¦£¬¹§Ï²Äã");
rs.close();
stmt.close();
conn.close();
}
}
......
ת×Ôhttp://www.zhenhua.org/article.asp?id=200
select * from table LIMIT 5,10; #·µ»ØµÚ6-15ÐÐÊý¾Ý
select * from table LIMIT 5; #·µ»ØÇ°5ÐÐ
select * from table LIMIT 0,5; #·µ»ØÇ°5ÐÐ
ÐÔÄÜÓÅ»¯£º
»ùÓÚMySQL5.0ÖÐlimitµÄ¸ßÐÔÄÜ,ÎÒ¶ÔÊý¾Ý·ÖÒ³Ò²ÖØÐÂÓÐÁËеÄÈÏʶ.
1.
Select * from cyclopedia Where ID>=(
Select Max(ID) from (
Select ID from cyclopedia Order By ID limit 90001
) As tmp
) limit 100;
2.
Select * from cyclopedia Where ID>=(
Select Max(ID) from (
Select ID from cyclopedia Order By ID limit 90000,1
) As tmp
) limit 100;
ͬÑùÊÇÈ¡90000Ìõºó100Ìõ¼Ç¼,µÚ1¾ä¿ì»¹ÊǵÚ2¾ä¿ì?
µÚ1¾äÊÇÏÈÈ¡ÁËǰ90001Ìõ¼Ç¼,È¡ÆäÖÐ×î´óÒ»¸öIDÖµ×÷ΪÆðʼ±êʶ,È»ºóÀûÓÃËü¿ÉÒÔ¿ìËÙ¶¨Î»ÏÂ100Ìõ¼Ç¼
µÚ2¾äÔñÊǽö½öÈ¡90000Ìõ¼Ç¼ºó1Ìõ,È»ºóÈ¡IDÖµ×÷Æðʼ±êʶ¶¨Î»ÏÂ100Ìõ¼Ç¼
µÚ1¾äÖ´Ðнá¹û.100 rows in set (0.23) sec
µÚ2¾äÖ´Ðнá¹û.100 rows in set (0.19) sec
ºÜÃ÷ÏÔµÚ2¾äʤ³ö.¿´À´limitºÃÏñ²¢²»ÍêÈ«ÏñÎÒ֮ǰÏëÏóµÄÄÇÑù×öÈ«±íɨÃè·µ»Ølimit offset+lengthÌõ¼Ç¼,ÕâÑù¿´À´limit±ÈÆðMS-SQLµÄTopÐÔÄÜ»¹ÊÇÒªÌá¸ß²»ÉÙµÄ.
Æä ......
ÒýÓÃhttp://bbs.51cto.com/thread-36865-1.html
ÏÂÃæÊÇһЩѧϰÈçºÎÓÃMySQL½â¾öһЩ³£¼ûÎÊÌâµÄÀý×Ó¡£
¡¡¡¡
¡¡¡¡Ò»Ð©Àý×ÓʹÓÃÊý¾Ý¿â±í“shop”£¬°üº¬Ä³¸öÉÌÈ˵ÄÿƪÎÄÕÂ(ÎïÆ·ºÅ)µÄ¼Û¸ñ¡£¼Ù¶¨Ã¿¸öÉÌÈ˵ÄÿƪÎÄÕÂÓÐÒ»¸öµ¥¶ÀµÄ¹Ì¶¨¼Û¸ñ£¬ÄÇô(ÎïÆ·£¬ÉÌÈË)ÊǼǼµÄÖ÷¼ü¡£
¡¡¡¡
¡¡¡¡ÄãÄÜÕâÑù´´½¨Àý×ÓÊý¾Ý¿â±í£º
¡¡¡¡CREATE TABLE shop (
¡¡¡¡ article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
¡¡¡¡ dealer¡¡CHAR(20)¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ DEFAULT ''¡¡¡¡ NOT NULL,
¡¡¡¡ price¡¡ DOUBLE(16,2)¡¡¡¡¡¡¡¡¡¡¡¡ DEFAULT '0.00' NOT NULL,
¡¡¡¡ PRIMARY KEY(article, dealer));
¡¡¡¡
¡¡¡¡INSERT INTO shop VALUES
¡¡¡¡(1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69),
¡¡¡¡(3,'D',1.25),(4,'D',19.95);
¡¡¡¡
¡¡¡¡ºÃÁË£¬Àý×ÓÊý¾ÝÊÇÕâÑùµÄ£º
¡¡¡¡
¡¡¡¡SELECT * from shop
¡¡¡¡
¡¡¡¡+---------+--------+-------+
¡¡¡¡| article | dealer | price |
¡¡¡¡+---------+--------+-------+
¡¡¡¡|¡¡¡¡0001 | A¡¡¡¡¡¡|¡¡3.45 |
¡¡¡¡|¡¡¡¡0001 | B¡¡¡¡¡¡|¡¡3.99 |
¡¡¡¡|¡¡¡¡0002 | A¡¡¡¡¡¡| 10.99 |
¡¡¡¡|¡¡¡¡0003 | B¡¡¡¡¡¡|¡¡1. ......
ÒýÓÃhttp://bbs.51cto.com/thread-602842-1.html
¼Ç¼һЩselectµÄ¼¼ÇÉ£º ¡¡¡¡1¡¢selectÓï¾ä¿ÉÒÔÓûسµ·Ö¸ô
$sql="select * from article where id=1"
¡¡¡¡ºÍ$sql="select * from article
¡¡¡¡ where id=1"£¬¶¼¿ÉÒԵõ½ÕýÈ·µÄ½á¹û£¬µ«ÓÐʱ·Ö¿ªÐ´»òÐíÄܸüÃ÷ÁËÒ»µã£¬ÌرðÊǵ±sqlÓï¾ä±È½Ï³¤Ê±
¡¡¡¡2¡¢ÅúÁ¿²éѯÊý¾Ý
¡¡¡¡¿ÉÒÔÓÃinÀ´ÊµÏÖ
$sql="select * from article where id in(1,3,5)"
¡¡¡¡3¡¢Ê¹ÓÃconcatÁ¬½Ó²éѯµÄ½á¹û
$sql="select concat(id,"-",con) as res from article where id=1"
¡¡¡¡·µ»Ø"1-article content"
¡¡¡¡4¡¢Ê¹ÓÃlocate
¡¡¡¡Ó÷¨£ºselect locate("hello","hello baby");·µ»Ø1
¡¡¡¡²»´æÔÚ·µ»Ø0
¡¡¡¡5¡¢Ê¹ÓÃgroup by
¡¡¡¡ÒÔǰһֱûÔõô¸ãÃ÷group by ºÍ order by£¬ÆäʵҲÂú¼òµ¥µÄ£¬group by ÊǰÑÏàͬµÄ½á¹û±àΪһ×é
exam£º$sql="select city ,count(*) from customer group by city";
¡¡¡¡Õâ¾ä»°µÄÒâ˼¾ÍÊÇ´Ócustomer±íÀïÁгöËùÓв»Öظ´µÄ³ÇÊУ¬¼°ÆäÊýÁ¿£¨ÓеãÀàËÆdistinct£©
¡¡¡¡group by ¾³£ÓëAVG(),MIN(),MAX(),SUM(),COUNT()Ò»ÆðʹÓÃ
¡¡¡¡6 ......
Ãâ±à³Ì£¬3²½¸ã¶¨´¿ÕæIPÊý¾Ýµ¼Èëµ½MySQLÏê½â
×÷Õߣº dawoniu.com
ǰÌ᣺ Äã»áÓÃvi¡£ ºÜÃ÷ÏÔ£¬±¾ÎÄÊÇÔÚLinuxϲâÊÔͨ¹ýµÄ¡£±¾ÎÄÓõÄÊÇMySQLÃüÁîÐй¤¾ß£¬Èç¹ûÄã²»»á£¬ÓÃphpMyAdminÓ¦¸ÃÒ²¿ÉÒÔ¡£
µÚ1²½£º ÏÂÔØ´¿ÕæIPÊý¾Ý£¬½âѹ´æ³Éip.txt¡£
Ïê½â£ºÕâÒ»²½²»ÓÃÏê½âÁ˰ɡ£Èç¹ûÄãÕâÒ»²½¶¼²»»á£¬ÏÂÃæ¾Í²»Óÿ´ÁË¡£
µÚ2²½£º ÓÃvi ±à¼ ip.txt¡£
# vi ip.txt
ÔÚvi½çÃæÏÂÊäÈëÈçÏÂÃüÁ
:%s/\s\+/;/
Ò»¹²Öظ´ÊäÈë3´Î¡£
´æÅÌÍ˳ö£º
£ºwq
Ïê½â£ºip.txtÓÐ4ÁС£·Ö±ðÊÇÆðʼip£¬
½áÊøip£¬µØÇø£¬ËµÃ÷¡£ÁÐÖ®¼äÓò»µÈÊýÁ¿µÄ¿Õ¸ñ¼ä¸ô¡£ÎªÁ˽«´ËÎı¾Îļþµ½Èëµ½mysql£¬ÐèÒª´¦ÀíµôÕâЩ¿Õ¸ñ¡£µ«ÊÇÖ»ÄÜ´¦Àíµôǰ3ÁеĿոñ£¬×îºóÒ»ÁÐÖеÄ
¿Õ¸ñÒª±£Áô¡£viÖÐÊäÈëµÄÃüÁîÒâ˼ÊÇ£¬°ÑÿһÐеÚÒ»¸öºÍÆäÁ¬ÐøµÄ¿Õ¸ñÌæ»»³É×Ö·û';'¡£
%s´ú±íÈ«¾ÖËÑË÷Ìæ»»¡£\s´ú±í¿Õ¸ñ¡£\+´ú±í¾¡¿ÉÄÜ¶àµØÆ¥ÅäÇ°ÃæµÄ×Ö·û¡£;´ú±íÌæ»»³É';'
µÚ3²½: µ¼ÈëMySQL
´´½¨MySQL±í
CREATE
TABLE
`ips`
.
`ip`
(
`ip_start`
VARCHAR
(
16
)
NOT
NULL
,
`ip_end`
VARCHAR
(
16
)
NULL
,
`region`
VARCHAR
(
128
)
NULL
,
`comments`
VARCHAR
(
512
)
NULL ......