mysql

瀛楃锛�

char(10)->瀹氶暱銆�10涓瓧绗﹀搴︺�傚鏋滃彸渚т笉澶燂紝鍒欑┖鏍艰ˉ榻愶紝鍙栧嚭鏉ョ殑鏃跺�欏垹闄ょ┖鏍笺��

varchar(10)->鍙橀暱銆佹渶澶�10涓瓧绗�

濡傦細瀛樺鍚嶇殑鏃跺�欙紝娌″繀瑕佷负浜嗛偅鍑犱釜闀垮害鍘讳娇鐢╲archar锛屼娇鐢ㄥ畾闀垮幓瀛樺偍浼氭彁楂樻晥鐜囷紒

鏃ユ湡鏃堕棿锛�

Year->1瀛楄妭->95||1995->銆�1901-2155銆�

Date->鏃ユ湡->1998-12-31->銆�1000-01-01->9999-12-31銆�

Time->鏃堕棿->13:56:23->->銆�-838:59:59->838:59:59銆�

datetime->鏃堕棿鎴�->1970-01-01 00:00:00鍒板綋鍓嶇殑绉掓暟

Tip锛欴ate聽 Date聽 datetime鍦╥nsert鐨勬椂鍊欓渶瑕佸姞涓婂紩鍙� 銆佸疄闄呭紑鍙戜腑锛屼竴鑸笉鏄敤杩欎簺锛岀洿鎺ヤ娇鐢�787657676绫讳技浜庤繖涓牱瀛愮殑鏁村舰鏉ュ瓨鍌紙鍏跺疄灏辨槸浠�1970骞�0鐐逛负鍑嗭紝鐒跺悗鎹㈢畻鎴愮鏁板瓨鍌級銆傛悶iOS寮�鍙戠殑鑲畾閬囧埌杩�

not null:

1銆丯ULL鏌ヨ涓嶄究銆佺储寮曟晥鐜囦笉楂樸�佹墍浠ュ疄鐢ㄤ腑閬垮厤鍒楃殑鍊间负NULL

2銆佸0鏄庡垪鐨勫�间负NOT NULL锛屽苟涓攄efault涓�涓粯璁ゅ��

涓婚敭涓庤嚜澧烇細

涓婚敭primary key姝ゅ垪涓嶉噸澶嶏紝灏辫兘澶熷尯鍒嗘瘡涓�琛岋紒

涓�涓〃涓彧鑳芥湁涓�涓猘uto_increment,鑰屼笖杩欎竴鍒楀繀椤诲姞涓妏rimary key绱㈠紩

淇敼鍒楋細

alter table tableName add 鍒楀悕 绫诲瀷 灞炴��... ->榛樿鍦╰able鐨勬渶鍚�

alter table tableName add 鍒楀悕 绫诲瀷 灞炴�� after 鍒跺畾鍒楀悕->灏嗗鍔犲埌鍒跺畾鐨勫垪鍚嶅悗闈�

alter table tableName drop column 鍒楀悕

alter table tableName change 鍒楀悕 鏂板悕瀛� 绫诲瀷 灞炴��...

alter table tableName modify 鍒楀悕 鏂板睘鎬�...

change鍙互淇敼鍒楀悕锛屼絾鏄痬odify涓嶈兘淇敼鍒楁槑锛屽彧鑳戒慨鏀瑰垪鐨勫睘鎬�

瑙嗗浘(View):

create view vgoods as select goods_name , goods_id from goods;

view鍙堣绉颁负铏氭嫙琛紝view鏄痵ql璇彞鐨勪竴涓煡璇㈢粨鏋溿��

濂藉锛�

1銆佹潈闄愭帶鍒舵椂鍙互鐢紱濡傦細鏌愬嚑涓垪鍏佽鐢ㄦ埛鏌ヨ锛屽叾浠栧垪涓嶅彲浠ャ��

create view tmpview as select goods_name from goods;

select * from tmpview;

2銆佺畝鍖栧鏉傜殑鏌ヨ锛�

3銆佷慨鏀圭墿鐞嗚〃锛岃櫄鎷熻〃涓�瀹氫細琚慨鏀癸紱濡傛灉鐗╃悊琛ㄥ畬鍏� 涓� 涓�瀵瑰簲鐫�铏氭嫙琛紝鍒欎慨鏀硅櫄鎷熻〃浼氭槧灏勫埌鐗╃悊琛ㄣ�備絾鏄紝姣斿铏氭嫙琛ㄦ槸姹傚钩鍧囦箣绫荤殑锛屼笉鏄竴涓�瀵瑰簲鐨勶紝鍒欎笉鑳戒慨鏀硅櫄鎷熻〃锛屽洜涓烘病娉曠‘璁ゅ埌鐗╃悊琛ㄧ殑鍏蜂綋鐨勬煇涓�涓綅缃��

鏌ヨview鏈変袱绉嶅彲鑳斤細

1銆佸皢鍒涘缓view鐨勮鍙ュ拰鏌ヨview鐨勮鍙ュ悎骞讹紝鐒跺悗鐩存帴鏌ョ墿鐞嗚〃銆傝繖绉嶆柟寮忓彨鍋歮erge

2銆佸鏋渧iew鐨勫舰鎴愬氨姣旇緝澶嶆潅浜嗭紝閭i鍏堟煡璇㈢墿鐞嗚〃锛屽湪鍐呭瓨涓舰鎴愪竴涓獀iew锛岀劧鍚庡啀鏌ヨ杩欎釜view銆�

浣跨敤merge鏂瑰紡锛歝reate algorithm-merge view view1 as select ... from goods;

浣跨敤temptable:create algorithm-temptable view view2 as select ... from goods;

鑷繁鎼炰笉瀹氬氨璁╂暟鎹簱鑷姩鍐冲畾锛�

琛╘瑙嗗浘绠$悊璇彞锛�

鏌ョ湅鎵�鏈夎〃锛歴how tables锛�

鏌ョ湅缁撴瀯锛歞esc table/view-name锛�

鏌ョ湅寤鸿〃/瑙嗗浘杩囩▼锛歴how create 聽table/view 聽table/view-name锛�

鍒犻櫎琛�/瑙嗗浘锛歞rop table table/view-name锛�

鏌ョ湅琛ㄧ殑璇︾粏淇℃伅锛歴how table status锛涘姞涓奬G浼氱珫鐫�鏄剧ず

鏀硅〃鍚嶏細rename table old-name to new-name;

娓呯┖琛ㄦ暟鎹細truncate锛�

delete鍜宼runcate鐨勫尯鍒細

delete 聽from table-name where id = 2锛�(id鏄痑uto_increment鐨�)锛屼笅娆″啀鎻掑叆涓�涓暟鎹殑鏃跺�欙紝id浼氱洿鎺ヤ粠3寮�濮嬶紝鑰屼笉浼氫粠2寮�濮嬶紝鍗充娇id=2鐨勫凡缁忚鍒犳帀銆�

truncate table-name;鐩稿綋浜庢墽琛屼簡涓ゆ锛岄鍏坉rop鎺夎繖涓猼able銆傜劧鍚庡張閲嶆柊寤虹珛涓�娆★紒

鎵�浠�...鑷繁浣撲細

瀛樺偍寮曟搸锛�

Myisam:鍗曠函鐨勫瓨鍙栬�屽凡锛屾病鏈変粈涔堟鏌ヤ箣绫荤殑锛�

InnoDB:瀛樺彇閮芥湁妫�鏌ワ紝鏈夎嚜宸辩殑鏃ュ織锛�

浠ヤ笂涓よ�呭弬鑰冪嚂鍗佸叓鐨勬瘮鍠�!

eg锛歝reate....( ... ) engine-InnoDB default charset-utf8;

瀛楃闆嗕贡鐮侀棶棰橈細

鏂囨湰鏈潵鐨勫瓧绗﹂泦涓庡睍绀虹殑瀛楃闆嗕笉涓�鑷村氨瀵艰嚧浜嗕贡鐮侊紒

鎴戣瀛樼殑绫诲瀷鏄痝bk/utf8锛歴et character_set_client = gbk/utf8;

鎴戣鍙栨暟鎹紝璇疯繑鍥炵粰鎴慻bk/utf8绫诲瀷鐨勬暟鎹細set character_set_result = gbk/utf8;

杩炴帴鍣ㄤ笉瑕佽缃瘮杈冨皬鐨勫瓧绗﹂泦锛屼笉鐒朵細鎹熷け鎺夋暟鎹紝鑰屼笖鏄笉鍙�嗙殑锛�

濡傛灉client銆乺esult銆乧onnect閮借缃负鍚屼竴鏍峰瓧绗﹂泦锛屾瘮濡倁tf8锛岄偅灏卞彲浠ョ洿鎺ョ畝鍐欎负set names utf8锛�

涔辩爜鐨勮瘽妫�鏌ュ洓涓湴鏂癸細php鏂囦欢绫诲瀷銆乸hp mate绫诲瀷(meta charset='utf-8')銆佸垱寤虹殑table鐨勭被鍨嬨�佹湁娌℃湁鎵цset names utf8锛�

鏍″闆嗗氨鏄竴绉嶆帓搴忚鍒欍��

绱㈠紩锛�

浣滅敤锛�

1銆佺储寮曞氨鐩稿綋浜庢暟鎹殑鐩綍锛岃兘蹇�熷畾浣嶆暟鎹殑浣嶇疆銆�

2銆佺储寮曟槸鏈変唬浠风殑锛屽畠鎻愰珮浜嗘煡璇㈢殑閫熷害锛屼絾鏄崯鑰椾簡澧炲垹鏀圭殑鏁堢巼銆�

3銆佷竴鑸湪鏌ヨ姣旇緝棰戠箒鐨勫垪涓婂姞绱㈠紩锛岃�屼笖閲嶅鐜囦綆鐨勭殑鍒椾笂鏁堟灉鏇村ソ銆傛瘮濡傦細鎬у埆锛屽彧鏈夌敺銆佸コ(shit锛屽叾浠栫殑涓嶈�冭檻)锛屾墍鏈夊氨娌″繀瑕佸姞涓婄储寮曘��

绫诲瀷锛�

鏅�氱储寮昸ey銆佸敮涓�绱㈠紩unique key銆佷富閿储寮昿rimary key銆佸叏鏂囩储寮�(鍦ㄤ腑鏂囩幆澧冧笅鏃犳晥,涓�鑸敤绗笁鏂圭殑瑙e喅鏂规)

绱㈠紩鍦ㄦ墍鏈夌殑鍒楄缃畬浜嗕箣鍚庤缃紒


mysql_第1张图片
璁剧疆绱㈠紩


璁剧疆绱㈠紩闀垮害


澶氬垪绱㈠紩

鍐椾綑绱㈠紩:

灏辨槸鍦ㄦ煇涓垪涓婂瓨鍦ㄥ涓储寮曘��

绱㈠紩鎿嶄綔锛�

show index from table-name \G;

alter table table-name drop index index-name;/drop index index-name on table-name; 聽(鍒犻櫎绱㈠紩)

alter table table-name add index unique index-name(line-name);(澧炲姞绱㈠紩)

alter table table-name add primary key (line-name);(澧炲姞涓婚敭绱㈠紩锛屼笉闇�瑕佺储寮曞悕)

alter table table-name drop primary key;(鍒犻櫎涓婚敭绱㈠紩)

浜嬪姟锛氾紙myisam涓嶆敮鎸佷簨鍔★級

鐗规�э細闅旂鎬с�佸師瀛愭�с�佷竴鑷存�с�佹寔涔呮�э紙涓�鏃ommit涔嬪悗锛屽氨娌℃硶rollback锛夈��

start transaction;鍚敤浜嬪姟

commit;纭

rollback;鍥炴粴

鎴戠畻鏄煡閬撲粈涔堟槸浜嬪姟浠�涔堜簨鍥炴粴浜嗭紒锛�

你可能感兴趣的:(mysql)