mysql±äÁ¿ÀàÐÍ
9.3. Óû§±äÁ¿
¿ÉÒÔÏÈÔÚÓû§±äÁ¿Öб£´æֵȻºóÔÚÒÔºóÒýÓÃËü£»ÕâÑù¿ÉÒÔ½«Öµ´ÓÒ»¸öÓï¾ä´«µÝµ½ÁíÒ»¸öÓï¾ä¡£Óû§±äÁ¿ÓëÁ¬½ÓÓйØ
¡£Ò²¾ÍÊÇ˵£¬Ò»¸ö¿Í»§¶Ë¶¨ÒåµÄ±äÁ¿²»Äܱ»ÆäËü¿Í»§¶Ë¿´µ½»òʹÓᣵ±¿Í»§¶ËÍ˳öʱ£¬¸Ã¿Í»§¶ËÁ¬½ÓµÄËùÓбäÁ¿½«×Ô¶¯ÊÍ·Å¡£
Óû§±äÁ¿µÄÐÎʽΪ@var_name
£¬ÆäÖбäÁ¿Ãûvar_name
¿ÉÒÔÓɵ±Ç°×Ö·û¼¯µÄÎÄ×ÖÊý×Ö×Ö·û¡¢‘.
’¡¢‘_
’ºÍ‘$
’×é³É¡£
ĬÈÏ×Ö·û¼¯ÊÇcp1252
(Latin1)
¡£¿ÉÒÔÓÃmysqld
µÄ--default-character-set
Ñ¡Ïî¸ü¸Ä×Ö·û¼¯¡£²Î¼û5.10.1½Ú£¬“Êý¾ÝºÍÅÅÐòÓÃ×Ö·û¼¯”
¡£Óû§±äÁ¿Ãû¶Ô´óСд²»Ãô¸Ð¡£
ÉèÖÃÓû§±äÁ¿µÄÒ»¸ö;¾¶ÊÇÖ´ÐÐSET
Óï¾ä£º
SET @
var_name
=
expr
[, @
var_name
=
expr
] ...
¶ÔÓÚSET
£¬¿ÉÒÔʹÓÃ=
»ò:=
×÷Ϊ·ÖÅä·û¡£·ÖÅä¸øÿ¸ö±äÁ¿µÄexpr
¿ÉÒÔΪÕûÊý¡¢ÊµÊý¡¢×Ö·û´®»òÕßNULL
Öµ¡£
Ò²¿ÉÒÔÓÃÓï¾ä´úÌæSET
À´ÎªÓû§±äÁ¿·ÖÅäÒ»¸öÖµ¡£ÔÚÕâÖÖÇé¿öÏ£¬·ÖÅä·û±ØÐëΪ:=
¶ø²»ÄÜÓÃ=
£¬ÒòΪÔÚ·ÇSET
Óï¾äÖÐ=
±»ÊÓΪһ¸ö±È½Ï
²Ù×÷·û£º
mysql>
SET @t1=0, @t2=0, @t3=0;
mysql>
SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
+----------------------+------+------+------+
| @t1:=(@t2:=1)+@t3:=4 | @t1 | @t2 | @t3 |
+----------------------+------+------+------+
| 5 | 5 | 1 | 4 |
+----------------------+------+------+------+
Óû§±äÁ¿¿ÉÒÔÓÃÓÚ±í´ïʽÖС£Ä¿Ç°²»°üÀ¨Ã÷ÏÔÐèÒªÎÄ×ÖÖµµÄÉÏÏÂÎÄÖУ¬ÀýÈçSELECT
Óï¾äµÄLIMIT
×Ӿ䣬»òÕßLOAD
DATA
Óï¾äµÄIGNORE
number LINES
×Ӿ䡣
Èç¹ûʹÓÃûÓгõʼ»¯µÄ±äÁ¿£¬ÆäÖµÊÇNULL
¡£
Èç¹ûÓû§±äÁ¿·ÖÅäÁËÒ»¸ö×Ö·û´®Öµ£¬Æä×Ö·û¼¯ºÍУ¶Ô¹æÔòÓë¸Ã×Ö·û´®µÄÏàͬ¡£Óû§±äÁ¿µÄ¿ÉѹËõÐÔ£¨coercibility
£©ÊÇÒþº¬µÄ¡£(
¼´Îª±íÁÐÖµµÄÏàͬµÄ¿ÉѹËõÐÔ£¨coercibility
£©¡£
×¢ÊÍ£º
ÔÚSELECT
Óï¾äÖУ¬±í´ïʽ·¢Ë͵½¿Í»§¶Ëºó²Å½øÐмÆËã¡£Õâ˵Ã÷ÔÚHAVING
¡¢GROUP
BY
»òÕßORDER
BY
×Ó¾äÖУ¬²»ÄÜʹÓðüº¬SELECT
ÁбíÖÐËùÉèµÄ±äÁ¿µÄ±í´ïʽ¡£ÀýÈ磬ÏÂÃæµÄÓï¾ä²»ÄÜ°´ÆÚÍû¹¤×÷£º
mysql>
SELECT (@aa:=id) AS a
£¬(@aa+3) AS b
´Ó
Ïà¹ØÎĵµ£º
½«ExcelÊý¾Ýµ¼ÈëMySql
1.½«Ñ¡ÖеÄÊý¾Ý¿ì¶ù¿½±´µ½Ò»¸öTXTÎı¾ÎļþÖУ¨¼ÇµÃ°ÑºóÃæµÄ¿Õ¸ñÏûµô¡£¡££©£¬¼ÙÈç´æµ½“D:\data.txt”Õâ¸öλÖÃÀï¡£
2.¸ù¾ÝÒªµ¼ÈëµÄÊý¾Ý¿ì¶ù½¨Á¢MySqlÊý¾Ý¿âºÍ±í£¬È»ºó½øÈëÃüÁîÌáʾ·ûÀïʹÓÃÃüÁî
load data local infile 'D:\data.txt' into table exceltomysql fields terminated ......
À´Ô´£ºhttp://www.sudone.com/linux/mysql_debug.html
×÷ÕߣºAyou
ÎÒÒ»Ö±ÊÇʹÓÃmysqlÕâ¸öÊý¾Ý¿âÈí¼þ£¬Ëü¹¤×÷±È½ÏÎȶ¨£¬Ð§ÂÊÒ²ºÜ¸ß¡£ÔÚÓöµ½ÑÏÖØÐÔÄÜÎÊÌâʱ£¬Ò»°ã¶¼ÓÐÕâô¼¸ÖÖ¿ÉÄÜ£º
1¡¢Ë÷ÒýûÓн¨ºÃ£»
2¡¢sqlд·¨¹ýÓÚ¸´ÔÓ£»
3¡¢ÅäÖôíÎó£»
4¡¢»úÆ÷ʵÔÚ¸ººÉ²»ÁË£»
1¡¢Ë÷ÒýûÓн¨ºÃ
Èç¹û¿´µ½mysqlÏûºÄµÄcpuºÜ´ó£¬¿ÉÒÔÓ ......
ΪʲôѡÔñÔ´Âë±àÒë°²×°mysql£ºÎÒÔÚʹÓÃrpm»òÕßÊÇyum°²×°Ê±myql£¬ÀÏÊÇÌáʾÎÒÕÒ²»µ½*.sockÎļþ£¬ÕÒÁ˵ã
×ÊÁÏ˵ÊǸðüÊǷǹٷ½°æ±¾£¨Ã÷Ã÷Êǹٷ½ÏÂÔØ µÄ£©£¬ÆäÖÐÔÒòµ½ÏÖÔÚ»¹Ã»ÓиãÇå³þ¡£Ï£ÍûÖªÇéÈËÊ¿¸æÖª¡££¨¿ªÊ¼±àÒëµÄʱºò£¬ÏµÍ³»·¾³Ò»¶¨ÒªÅäÖúã¬GCC£¬GC++...µÈµÈµÄ±àÒëÆ÷Ò»¶¨Òª×öºÃ,±¾È˵ÄcentosÓÉÓÚ¿ªÊ¼
ϵͳ»·¾ ......
Æô¶¯£ºnet start mySql;
½øÈ룺mysql -u root -p/mysql -h localhost -u root -p databaseName;
ÁгöÊý¾Ý¿â£ºshow databases;
Ñ¡ÔñÊý¾Ý¿â£ºuse databaseName;
Áгö±í¸ñ£ºshow tables£»
ÏÔʾ±í¸ñÁеÄÊôÐÔ£ºshow columns from tableName£»
½¨Á¢Êý¾Ý¿â£ºsource fileNa ......