鎵€浠ュ湪鐪熷疄鐨勭敓浜х幆澧冧腑涓嶆帹鑽愪娇鐢?/strong>锛屽惁鍒欏湪璁$畻鏃讹紝鐢变簬绮惧害绫诲瀷闂锛屼細瀵艰嚧鏈€缁堢殑璁$畻缁撴灉鍑洪敊銆?/p>
鏇撮噸瑕佺殑鏄紝浠?MySQL 8.0.17 鐗堟湰寮€濮嬶紝褰撳垱寤鸿〃鐢ㄥ埌绫诲瀷 Float 鎴?Double 鏃讹紝浼氭姏鍑轰笅闈㈢殑璀﹀憡锛歁ySQL 鎻愰啋鐢ㄦ埛涓嶈鐢ㄤ笂杩版诞鐐圭被鍨嬶紝鐢氳嚦鎻愰啋灏嗗湪涔嬪悗鐗堟湰涓簾寮冩诞鐐圭被鍨嬨€?/p>
Specifying number of digits for floating point data types is deprecated and will be removed in a future release
鑰屾暟瀛楃被鍨嬩腑鐨勯珮绮惧害 DECIMAL 绫诲瀷鍙互浣跨敤锛屽綋澹版槑璇ョ被鍨嬪垪鏃讹紝鍙互锛堝苟涓旈€氬父蹇呴』瑕侊級鎸囧畾绮惧害鍜屾爣搴︼紝渚嬪锛?/p>
salary DECIMAL(8,2)
鍏朵腑锛? 鏄簿搴︼紙绮惧害琛ㄧず淇濆瓨鍊肩殑涓昏浣嶆暟锛夛紝2 鏄爣搴︼紙鏍囧害琛ㄧず灏忔暟鐐瑰悗闈繚瀛樼殑浣嶆暟锛夈€傞€氬父鍦ㄨ〃缁撴瀯璁捐涓紝绫诲瀷 DECIMAL 鍙互鐢ㄦ潵琛ㄧず鐢ㄦ埛鐨勫伐璧勩€佽处鎴风殑浣欓绛夌簿纭埌灏忔暟鐐瑰悗 2 浣嶇殑涓氬姟銆?/p>
鐒惰€岋紝鍦ㄦ捣閲忓苟鍙戠殑浜掕仈缃戜笟鍔′腑浣跨敤锛岄噾棰濆瓧娈电殑璁捐骞朵笉鎺ㄨ崘浣跨敤 DECIMAL 绫诲瀷锛岃€屾洿鎺ㄨ崘浣跨敤 INT 鏁村瀷绫诲瀷锛堜笅鏂囧氨浼氬垎鏋愬師鍥狅級銆?/p>
涓氬姟琛ㄧ粨鏋勮璁″疄鎴?/span>
鏁村瀷绫诲瀷涓庤嚜澧炶璁?/span>
鍦ㄧ湡瀹炰笟鍔″満鏅腑锛屾暣鍨嬬被鍨嬫渶甯歌鐨勫氨鏄湪涓氬姟涓敤鏉ヨ〃绀烘煇浠剁墿鍝佺殑鏁伴噺銆備緥濡備笂杩拌〃鐨勯攢鍞暟閲忥紝鎴栫數鍟嗕腑鐨勫簱瀛樻暟閲忋€佽喘涔版鏁扮瓑銆傚湪涓氬姟涓紝鏁村瀷绫诲瀷鐨勫彟涓€涓父瑙佷笖閲嶈鐨勪娇鐢ㄧ敤娉曟槸浣滀负琛ㄧ殑涓婚敭锛屽嵆鐢ㄦ潵鍞竴鏍囪瘑涓€琛屾暟鎹€?/p>
鏁村瀷缁撳悎灞炴€?auto_increment锛屽彲浠ュ疄鐜?span class="mq-150">鑷鍔熻兘锛屼絾鍦ㄨ〃缁撴瀯璁捐鏃剁敤鑷鍋氫富閿紝甯屾湜浣犵壒鍒娉ㄦ剰浠ヤ笅涓ょ偣锛岃嫢涓嶆敞鎰忥紝鍙兘浼氬涓氬姟閫犳垚鐏鹃毦鎬х殑鎵撳嚮锛?/p>
-
鐢?BIGINT 鍋氫富閿紝鑰屼笉鏄?INT锛?
-
鑷鍊煎苟涓嶆寔涔呭寲锛屽彲鑳戒細鏈夊洖婧幇璞★紙MySQL 8.0 鐗堟湰鍓嶏級銆?
浠庤〃 1 鍙互鍙戠幇锛孖NT 鐨勮寖鍥存渶澶у湪 42 浜跨殑绾у埆锛屽湪鐪熷疄鐨勪簰鑱旂綉涓氬姟鍦烘櫙鐨勫簲鐢ㄤ腑锛屽緢瀹规槗杈惧埌鏈€澶у€笺€備緥濡備竴浜涙祦姘磋〃銆佹棩蹇楄〃锛屾瘡澶?1000W 鏁版嵁閲忥紝420 澶╁悗锛孖NT 绫诲瀷鐨勪笂闄愬嵆鍙揪鍒般€?/p>
鍥犳锛岋紙鏁查粦鏉?1锛?span class="mq-156">鐢ㄨ嚜澧炴暣鍨嬪仛涓婚敭锛屼竴寰嬩娇鐢?BIGINT锛岃€屼笉鏄?INT銆備笉瑕佷负浜嗚妭鐪?4 涓瓧鑺備娇鐢?INT锛屽綋杈惧埌涓婇檺鏃讹紝鍐嶈繘琛岃〃缁撴瀯鐨勫彉鏇达紝灏嗘槸宸ㄥぇ鐨勮礋鎷呬笌鐥涜嫤銆?/p>
閭h繖閲屽張寮曠敵鍑轰竴涓湁鎰忔€濈殑闂锛氬鏋滆揪鍒颁簡 INT 绫诲瀷鐨勪笂闄愶紝鏁版嵁搴撶殑琛ㄧ幇鍙堝皢濡備綍鍛紵鏄細閲嶆柊鍙樹负 1锛熸垜浠彲浠ラ€氳繃涓嬮潰鐨?SQL 璇彞楠岃瘉涓€涓嬶細
mysql> CREATE TABLE t (
-> a INT AUTO_INCREMENT PRIMARY KEY
-> );
mysql> INSERT INTO t VALUES (2147483647);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO t VALUES (NULL);
ERROR 1062 (23000): Duplicate entry '2147483647' for key 't.PRIMARY'
鍙互鐪嬪埌锛屽綋杈惧埌 INT 涓婇檺鍚庯紝鍐嶆杩涜鑷鎻掑叆鏃讹紝浼氭姤閲嶅閿欒锛孧ySQL 鏁版嵁搴撳苟涓嶄細鑷姩灏嗗叾閲嶇疆涓?1銆?/p>
绗簩涓壒鍒娉ㄦ剰鐨勯棶棰樻槸锛岋紙鏁查粦鏉?2锛?span class="mq-175">MySQL 8.0 鐗堟湰鍓嶏紝鑷涓嶆寔涔呭寲锛岃嚜澧炲€煎彲鑳戒細瀛樺湪鍥炴函闂锛?/p>
mysql> SELECT * FROM t;
+---+
| a |
+---+
| 1 |
| 2 |
| 3 |
+---+
3 rows in set (0.01 sec)
mysql> DELETE FROM t WHERE a = 3;
Query OK, 1 row affected (0.02 sec)
mysql> SHOW CREATE TABLE t\G
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`a` int NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
1 row in set (0.00 sec
鍙互鐪嬪埌锛屽湪鍒犻櫎鑷涓?3 鐨勮繖鏉¤褰曞悗锛屼笅涓€涓嚜澧炲€间緷鐒朵负 4锛圓UTO_INCREMENT=4锛夛紝杩欓噷骞舵病鏈夐敊璇紝鑷骞朵笉浼氳繘琛屽洖婧€備絾鑻ヨ繖鏃舵暟鎹簱鍙戠敓閲嶅惎锛岄偅鏁版嵁搴撳惎鍔ㄥ悗锛岃〃 t 鐨勮嚜澧炶捣濮嬪€煎皢鍐嶆鍙樹负 3锛屽嵆鑷鍊煎彂鐢熷洖婧€傚叿浣撳涓嬫墍绀猴細
mysql> SHOW CREATE TABLE t\G
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
`a` int NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
1 row in set (0.00 s
鑻ヨ褰诲簳瑙e喅杩欎釜闂锛屾湁浠ヤ笅 2 绉嶆柟娉曪細
-
鍗囩骇 MySQL 鐗堟湰鍒?8.0 鐗堟湰锛屾瘡寮犺〃鐨勮嚜澧炲€间細鎸佷箙鍖栵紱
-
鑻ユ棤娉曞崌绾ф暟鎹簱鐗堟湰锛屽垯寮虹儓涓嶆帹鑽愬湪鏍稿績涓氬姟琛ㄤ腑浣跨敤鑷鏁版嵁绫诲瀷鍋氫富閿€?
鍏跺疄锛屽湪娴烽噺浜掕仈缃戞灦鏋勮璁¤繃绋嬩腑锛屼负浜嗕箣鍚庢洿濂界殑鍒嗗竷寮忔灦鏋勬墿灞曟€э紝涓嶅缓璁娇鐢ㄦ暣鍨嬬被鍨嬪仛涓婚敭锛屾洿涓烘帹鑽愮殑鏄瓧绗︿覆绫诲瀷銆?/p>
璧勯噾瀛楁璁捐
鍦ㄧ敤鎴蜂綑棰濄€佸熀閲戣处鎴蜂綑棰濄€佹暟瀛楅挶鍖呫€侀浂閽辩瓑鐨勪笟鍔¤璁′腑锛岀敱浜庡瓧娈甸兘鏄祫閲戝瓧娈碉紝閫氬父绋嬪簭鍛樹範鎯娇鐢?DECIMAL 绫诲瀷浣滀负瀛楁鐨勯€夊瀷锛屽洜涓鸿繖鏍峰彲浠ョ簿纭埌鍒嗭紝濡傦細DECIMAL(8,2)銆?/p>
CREATE TABLE User (
userId BIGINT AUTO_INCREMENT,
money DECIMAL(8,2) NOT NULL,
......
)
锛堟暡榛戞澘3锛?span class="mq-274">鍦ㄦ捣閲忎簰鑱旂綉涓氬姟鐨勮璁℃爣鍑嗕腑锛屽苟涓嶆帹鑽愮敤 DECIMAL 绫诲瀷锛岃€屾槸鏇存帹鑽愬皢 DECIMAL 杞寲涓?鏁村瀷绫诲瀷銆?/strong> 涔熷氨鏄锛岃祫閲戠被鍨嬫洿鎺ㄨ崘浣跨敤鐢ㄥ垎鍗曚綅瀛樺偍锛岃€屼笉鏄敤鍏冨崟浣嶅瓨鍌ㄣ€傚1鍏冨湪鏁版嵁搴撲腑鐢ㄦ暣鍨嬬被鍨?100 瀛樺偍銆?/p>
閲戦瀛楁鐨勫彇鍊艰寖鍥村鏋滅敤 DECIMAL 琛ㄧず鐨勶紝濡備綍瀹氫箟闀垮害鍛紵鍥犱负绫诲瀷 DECIMAL 鏄釜鍙橀暱瀛楁锛岃嫢瑕佸畾涔夐噾棰濆瓧娈碉紝鍒欏畾涔変负 DECIMAL(8,2) 鏄繙杩滀笉澶熺殑銆傝繖鏍峰彧鑳借〃绀哄瓨鍌ㄦ渶澶у€间负 999999.99锛岀櫨涓囩骇鐨勮祫閲戝瓨鍌ㄣ€?/p>
鐢ㄦ埛鐨勯噾棰濊嚦灏戣瀛樺偍鐧句嚎鐨勫瓧娈碉紝鑰岀粺璁″眬鐨?GDP 閲戦瀛楁鍒欏彲鑳借揪鍒版暟鍗佷竾浜跨骇鍒€傜敤绫诲瀷 DECIMAL 瀹氫箟锛屼笉濂界粺涓€銆?/p>
鍙﹀閲嶈鐨勬槸锛岀被鍨?DECIMAL 鏄€氳繃浜岃繘鍒跺疄鐜扮殑涓€绉嶇紪鐮佹柟寮忥紝璁$畻鏁堢巼杩滀笉濡傛暣鍨嬫潵鐨勯珮鏁堛€傚洜姝わ紝鎺ㄨ崘浣跨敤 BIG INT 鏉ュ瓨鍌ㄩ噾棰濈浉鍏崇殑瀛楁銆?/p>
瀛楁瀛樺偍鏃堕噰鐢ㄥ垎瀛樺偍锛屽嵆渚胯繖鏍?BIG INT 涔熻兘瀛樺偍鍗冨厗绾у埆鐨勯噾棰濄€傝繖閲岋紝1鍏?= 1涓囦嚎銆?/p>
杩欐牱鐨勫ソ澶勬槸锛屾墍鏈夐噾棰濈浉鍏冲瓧娈甸兘鏄畾闀垮瓧娈碉紝鍗犵敤 8 涓瓧鑺傦紝瀛樺偍楂樻晥銆傚彟涓€鐐癸紝鐩存帴閫氳繃鏁村瀷璁$畻锛屾晥鐜囨洿楂樸€?/p>
娉ㄦ剰锛?span class="mq-281">鍦ㄦ暟鎹簱璁捐涓紝鎴戜滑闈炲父寮鸿皟瀹氶暱瀛樺偍锛屽洜涓哄畾闀垮瓨鍌ㄧ殑鎬ц兘鏇村ソ銆?/strong>
鎴戜滑鏉ョ湅鍦ㄦ暟鎹簱涓褰曠殑瀛樺偍鏂瑰紡锛屽ぇ鑷村涓嬶細