mysql的数据类型都有哪些 MySql数据类型有哪些
Mysql\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u6709\u54ea\u4e9bMysql\u652f\u6301\u7684\u591a\u79cd\u6570\u636e\u7c7b\u578b\u4e3b\u8981\u6709\uff1a\u6570\u503c\u6570\u636e\u7c7b\u578b\u3001\u65e5\u671f/\u65f6\u95f4\u7c7b\u578b\u3001\u5b57\u7b26\u4e32\u7c7b\u578b\u3002 1.\u6574\u6570\u6570\u636e\u7c7b\u578b\u53ca\u5176\u53d6\u503c\u8303\u56f4\uff1a
\u7c7b\u578b
\u8bf4\u660e
\u5b58\u50a8\u9700\u6c42\uff08\u53d6\u503c\u8303\u56f4\uff09
tinyint \u5f88\u5c0f\u6574\u6570 1\u5b57\u8282\uff08[0~255]\u3001[-128~127]\uff09; 255=2^8-1;127=2^7-1
smallint \u5c0f\u6574\u6570 2\u5b57\u8282\uff080~65535\u3001-32768~32767\uff09 ;65535=2^16-1
mediumint \u4e2d\u7b49 3\u5b57\u8282\uff080~16777215\uff09 ;16777215=2^24-1
int(integer) \u666e\u901a 4\u5b57\u8282\uff080~4294967295\uff09 ;4294967295=2^32-1
bigint \u5927\u6574\u6570 8\u5b57\u8282\uff080~18446744073709551615\uff09;18446744073709551615=2^64-1
\u6d6e\u70b9\u6570&\u5b9a\u70b9\u6570\uff1a
\u7c7b\u578b\u540d\u79f0
\u8bf4\u660e
\u5b58\u50a8\u9700\u6c42
float \u5355\u7cbe\u5ea6\u6d6e\u70b9\u6570 4\u5b57\u8282
double \u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570 8\u5b57\u8282
decimal \u538b\u7f29\u7684\u201c\u4e25\u683c\u201d\u5b9a\u70b9\u6570 M+2\u5b57\u8282
\u6ce8\uff1a\u5b9a\u70b9\u6570\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u5b58\u50a8\uff0c\u5bf9\u7cbe\u5ea6\u8981\u6c42\u9ad8\u65f6\u4f7f\u7528decimal\u8f83\u597d\uff1b\u5c3d\u91cf\u907f\u514d\u5bf9\u6d6e\u70b9\u6570\u8fdb\u884c\u51cf\u6cd5\u548c\u6bd4\u8f83\u8fd0\u7b97\u3002 2.\u65f6\u95f4/\u65e5\u671f\u7c7b\u578b\uff1a year\u8303\u56f4\uff1a1901~2155; time\u683c\u5f0f\uff1a\u2018HH:MM:SS\u2019\uff08\u5982\u679c\u7701\u7565\u5199\uff0c\u5e76\u4e14\u6ca1\u6709\u5192\u53f7\uff0c\u5219\u9ed8\u8ba4\u6700\u53f3\u8d772\u4f4d\u4e3a\u79d2\uff0c\u518d\u5230\u5206\uff0c\u6700\u540e\u5230\u65f6\uff09\uff1b \u63d2\u5165\u7cfb\u7edf\u5f53\u524d\u65f6\u95f4\uff1ainsert into \u8868\u540d values(current_date()),(now()); date\u7c7b\u578b\uff1a\u2018YYYY-MM-DD\u2019\uff1b datetime\uff08\u65e5\u671f+\u65f6\u95f4\uff09\uff1a\u2018YYYY-MM-DD HH:MM:SS\u2019\u6216\u2018YYYYMMDDHHMMSS\u2019\uff0c\u53d6\u503c\u8303\u56f4\uff1a\u20181000-01-01 00:00:00\u2019~\u20189999-12-31 23:59:59\u2019\uff1b timestamp\u683c\u5f0f\u540cdatetime\uff0c\u4f46\u5728\u5b58\u50a8\u65f6\u9700\u89814\u4e2a\u5b57\u8282(datetime\u9700\u89818\u5b57\u8282)\uff0c\u5e76\u4e14\u4ee5UTC\uff08\u4e16\u754c\u6807\u51c6\u65f6\u95f4\uff09\u8fdb\u884c\u5b58\u50a8\uff08\u5373timestamp\u4f1a\u968f\u8bbe\u7f6e\u7684\u65f6\u533a\u800c\u53d8\u5316\uff0c\u800cdatetime\u5b58\u50a8\u7684\u7edd\u4e0d\u4f1a\u53d8\u5316\uff09\uff1btimestamp\u7684\u8303\u56f4\uff1a1970-2037\u3002 3.\u5b57\u7b26\u4e32\u7c7b\u578b\uff1a text\u7c7b\u578b\uff1atinytext\u3001text\u3001mediumtext\u3001longtext;
\u7c7b\u578b
\u8303\u56f4
tinytext 255=2^8-1
text 65535=2^16-1
mediumtext 16777215=2^24-1
longtext 4294967295=4GB=2^32-1
char\u7684\u5b58\u50a8\u9700\u6c42\u662f\u5b9a\u4e49\u65f6\u6307\u5b9a\u7684\u56fa\u5b9a\u957f\u5ea6\uff1bvarchar\u7684\u5b58\u50a8\u9700\u6c42\u662f\u53d6\u51b3\u4e8e\u5b9e\u9645\u503c\u957f\u5ea6\u3002 set\u7c7b\u578b\u683c\u5f0f\uff1aset\uff08\u2019\u503c1\u2019,\u2019\u503c2\u2019\u2026) \u2014\u2014\u53ef\u4ee5\u67090\u6216\u8005\u591a\u4e2a\u503c\uff0c\u5bf9\u4e8eset\u800c\u8a00\uff0c\u82e5\u63d2\u5165\u7684\u503c\u4e3a\u91cd\u590d\u7684\uff0c\u5219\u53ea\u5a36\u4e00\u4e2a\u3002\u63d2\u5165\u7684\u503c\u4e71\u5e8f\uff0c\u5219\u81ea\u52a8\u6309\u987a\u5e8f\u63d2\u5165\u6392\u5217\u3002\u63d2\u5165\u4e0d\u6b63\u5e38\u503c\uff0c\u5219\u5ffd\u7565\u3002 \u4e8c\u8fdb\u5236\u7c7b\u578b\uff1a bit\uff08M\uff09\u2014\u2014\u4fdd\u5b58\u4f4d\u5b57\u6bb5\u503c\uff08\u4f4d\u5b57\u6bb5\u7c7b\u578b\uff09\uff0cM\u8868\u793a\u503c\u7684\u4f4d\u6570\uff1b eg:select BIN(b+0) from \u8868\u540d\uff1b\u2014\u2013b\u4e3a\u5217\u540d;b+0\u8868\u793a\u5c06\u4e8c\u8fdb\u5236\u7684\u7ed3\u679c\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u6570\u5b57\u7684\u503c\uff0cBIN\uff08\uff09\u51fd\u6570\u5c06\u6570\u5b57\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u3002 blog\u2014\u2014-\u4e8c\u8fdb\u5236\u5927\u5bf9\u8c61\uff0c\u7528\u6765\u5b58\u50a8\u53ef\u53d8\u6570\u91cf\u7684\u6570\u636e\u3002
\u6570\u636e\u7c7b\u578b
\u5b58\u50a8\u8303\u56f4(\u5b57\u8282)
tinyblog \u6700\u591a255=2^8-1 \u5b57\u8282
bolg \u6700\u591a65535=2^16-1 \u5b57\u8282
mediumblog \u6700\u591a16777215=2^24-1 \u5b57\u8282
longblog \u6700\u591a4294967295=4GB=2^32-1 \u5b57\u8282
Mysql\u652f\u6301\u7684\u591a\u79cd\u6570\u636e\u7c7b\u578b\u4e3b\u8981\u6709\uff1a\u6570\u503c\u6570\u636e\u7c7b\u578b\u3001\u65e5\u671f/\u65f6\u95f4\u7c7b\u578b\u3001\u5b57\u7b26\u4e32\u7c7b\u578b\u3002 1.\u6574\u6570\u6570\u636e\u7c7b\u578b\u53ca\u5176\u53d6\u503c\u8303\u56f4\uff1a
\u7c7b\u578b
\u8bf4\u660e
\u5b58\u50a8\u9700\u6c42\uff08\u53d6\u503c\u8303\u56f4\uff09
tinyint \u5f88\u5c0f\u6574\u6570 1\u5b57\u8282\uff08[0~255]\u3001[-128~127]\uff09; 255=2^8-1;127=2^7-1
smallint \u5c0f\u6574\u6570 2\u5b57\u8282\uff080~65535\u3001-32768~32767\uff09 ;65535=2^16-1
mediumint \u4e2d\u7b49 3\u5b57\u8282\uff080~16777215\uff09 ;16777215=2^24-1
int(integer) \u666e\u901a 4\u5b57\u8282\uff080~4294967295\uff09 ;4294967295=2^32-1
bigint \u5927\u6574\u6570 8\u5b57\u8282\uff080~18446744073709551615\uff09;18446744073709551615=2^64-1
\u6d6e\u70b9\u6570&\u5b9a\u70b9\u6570\uff1a
\u7c7b\u578b\u540d\u79f0
\u8bf4\u660e
\u5b58\u50a8\u9700\u6c42
float \u5355\u7cbe\u5ea6\u6d6e\u70b9\u6570 4\u5b57\u8282
double \u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570 8\u5b57\u8282
decimal \u538b\u7f29\u7684\u201c\u4e25\u683c\u201d\u5b9a\u70b9\u6570 M+2\u5b57\u8282
\u6ce8\uff1a\u5b9a\u70b9\u6570\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u5b58\u50a8\uff0c\u5bf9\u7cbe\u5ea6\u8981\u6c42\u9ad8\u65f6\u4f7f\u7528decimal\u8f83\u597d\uff1b\u5c3d\u91cf\u907f\u514d\u5bf9\u6d6e\u70b9\u6570\u8fdb\u884c\u51cf\u6cd5\u548c\u6bd4\u8f83\u8fd0\u7b97\u3002 2.\u65f6\u95f4/\u65e5\u671f\u7c7b\u578b\uff1a year\u8303\u56f4\uff1a1901~2155; time\u683c\u5f0f\uff1a\u2018HH:MM:SS\u2019\uff08\u5982\u679c\u7701\u7565\u5199\uff0c\u5e76\u4e14\u6ca1\u6709\u5192\u53f7\uff0c\u5219\u9ed8\u8ba4\u6700\u53f3\u8d772\u4f4d\u4e3a\u79d2\uff0c\u518d\u5230\u5206\uff0c\u6700\u540e\u5230\u65f6\uff09\uff1b \u63d2\u5165\u7cfb\u7edf\u5f53\u524d\u65f6\u95f4\uff1ainsert into \u8868\u540d values(current_date()),(now()); date\u7c7b\u578b\uff1a\u2018YYYY-MM-DD\u2019\uff1b datetime\uff08\u65e5\u671f+\u65f6\u95f4\uff09\uff1a\u2018YYYY-MM-DD HH:MM:SS\u2019\u6216\u2018YYYYMMDDHHMMSS\u2019\uff0c\u53d6\u503c\u8303\u56f4\uff1a\u20181000-01-01 00:00:00\u2019~\u20189999-12-31 23:59:59\u2019\uff1b timestamp\u683c\u5f0f\u540cdatetime\uff0c\u4f46\u5728\u5b58\u50a8\u65f6\u9700\u89814\u4e2a\u5b57\u8282(datetime\u9700\u89818\u5b57\u8282)\uff0c\u5e76\u4e14\u4ee5UTC\uff08\u4e16\u754c\u6807\u51c6\u65f6\u95f4\uff09\u8fdb\u884c\u5b58\u50a8\uff08\u5373timestamp\u4f1a\u968f\u8bbe\u7f6e\u7684\u65f6\u533a\u800c\u53d8\u5316\uff0c\u800cdatetime\u5b58\u50a8\u7684\u7edd\u4e0d\u4f1a\u53d8\u5316\uff09\uff1btimestamp\u7684\u8303\u56f4\uff1a1970-2037\u3002 3.\u5b57\u7b26\u4e32\u7c7b\u578b\uff1a text\u7c7b\u578b\uff1atinytext\u3001text\u3001mediumtext\u3001longtext;
\u7c7b\u578b
\u8303\u56f4
tinytext 255=2^8-1
text 65535=2^16-1
mediumtext 16777215=2^24-1
longtext 4294967295=4GB=2^32-1
char\u7684\u5b58\u50a8\u9700\u6c42\u662f\u5b9a\u4e49\u65f6\u6307\u5b9a\u7684\u56fa\u5b9a\u957f\u5ea6\uff1bvarchar\u7684\u5b58\u50a8\u9700\u6c42\u662f\u53d6\u51b3\u4e8e\u5b9e\u9645\u503c\u957f\u5ea6\u3002 set\u7c7b\u578b\u683c\u5f0f\uff1aset\uff08\u2019\u503c1\u2019,\u2019\u503c2\u2019\u2026) \u2014\u2014\u53ef\u4ee5\u67090\u6216\u8005\u591a\u4e2a\u503c\uff0c\u5bf9\u4e8eset\u800c\u8a00\uff0c\u82e5\u63d2\u5165\u7684\u503c\u4e3a\u91cd\u590d\u7684\uff0c\u5219\u53ea\u5a36\u4e00\u4e2a\u3002\u63d2\u5165\u7684\u503c\u4e71\u5e8f\uff0c\u5219\u81ea\u52a8\u6309\u987a\u5e8f\u63d2\u5165\u6392\u5217\u3002\u63d2\u5165\u4e0d\u6b63\u5e38\u503c\uff0c\u5219\u5ffd\u7565\u3002 \u4e8c\u8fdb\u5236\u7c7b\u578b\uff1a bit\uff08M\uff09\u2014\u2014\u4fdd\u5b58\u4f4d\u5b57\u6bb5\u503c\uff08\u4f4d\u5b57\u6bb5\u7c7b\u578b\uff09\uff0cM\u8868\u793a\u503c\u7684\u4f4d\u6570\uff1b eg:select BIN(b+0) from \u8868\u540d\uff1b\u2014\u2013b\u4e3a\u5217\u540d;b+0\u8868\u793a\u5c06\u4e8c\u8fdb\u5236\u7684\u7ed3\u679c\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u6570\u5b57\u7684\u503c\uff0cBIN\uff08\uff09\u51fd\u6570\u5c06\u6570\u5b57\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u3002 blog\u2014\u2014-\u4e8c\u8fdb\u5236\u5927\u5bf9\u8c61\uff0c\u7528\u6765\u5b58\u50a8\u53ef\u53d8\u6570\u91cf\u7684\u6570\u636e\u3002
\u6570\u636e\u7c7b\u578b
\u5b58\u50a8\u8303\u56f4(\u5b57\u8282)
tinyblog \u6700\u591a255=2^8-1 \u5b57\u8282
bolg \u6700\u591a65535=2^16-1 \u5b57\u8282
mediumblog \u6700\u591a16777215=2^24-1 \u5b57\u8282
longblog \u6700\u591a4294967295=4GB=2^32-1 \u5b57\u8282
绛旓細MySQL鏁版嵁搴撲富瑕佹湁浠ヤ笅绫诲瀷锛1. 鍏崇郴鍨嬫暟鎹簱锛圧DBMS锛夊叧绯诲瀷鏁版嵁搴撴槸MySQL涓渶甯歌鍜屽簲鐢ㄦ渶骞挎硾鐨勬暟鎹簱绫诲瀷銆傚畠閲囩敤鍏崇郴妯″瀷鏉ュ瓨鍌ㄥ拰绠$悊鏁版嵁锛屼互琛ㄦ牸鐨勫舰寮忕粍缁囧拰瀛樺偍鏁版嵁锛屽叿鏈夊己澶х殑鏁版嵁鎿嶄綔鍔熻兘锛屽寘鎷暟鎹煡璇佹彃鍏ャ佹洿鏂板拰鍒犻櫎绛夈2. 鍒楀紡瀛樺偍鏁版嵁搴 鍒楀紡瀛樺偍鏁版嵁搴撴槸MySQL涓竴绉嶇壒娈婄殑鏁版嵁搴撶被鍨...
绛旓細MySQL鏀寔澶氱绫诲瀷锛澶ц嚧鍙互鍒嗕负鍥涚被锛氭暟鍊煎瀷銆佹诞鐐瑰瀷銆佹棩鏈/鏃堕棿鍜屽瓧绗︿覆(瀛楃)绫诲瀷銆1.鏁板煎瀷 MySQL鏀寔鎵鏈夋爣鍑哠QL鏁板兼暟鎹被鍨嬨傝繖浜涙暟鍊肩被鍨嬪寘鎷弗鏍兼暟鍊兼暟鎹被鍨(INTEGER銆丼MALLINT銆丏ECIMAL鍜孨UMERIC)锛屼互鍙婅繎浼兼暟鍊兼暟鎹被鍨(FLOAT銆丷EAL鍜孌OUBLE PRECISION)銆傚叧閿瓧INT鏄疘NTEGER鐨勫悓涔夎瘝锛屽叧閿瓧DEC鏄...
绛旓細Mysql鏀寔鐨勫绉嶆暟鎹被鍨嬩富瑕佹湁锛氭暟鍊兼暟鎹被鍨嬨佹棩鏈/鏃堕棿绫诲瀷銆佸瓧绗︿覆绫诲瀷銆1銆丮ysql鏀寔鎵鏈夋爣鍑哠QL涓殑鏁板肩被鍨嬶紝鍏朵腑鍖呮嫭鏁存暟鍨嬬殑tinyint鍜宐igint锛屽皬鏁板瀷鐨刣ecimal銆2銆丮ySQL鎻愪緵浜8涓熀鏈殑瀛楃涓茬被鍨,鍙互瀛樺偍鐨勮寖鍥翠粠绠鍗曠殑瀛楃鎴栦簩杩涘埗瀛楃涓叉暟鎹3銆佸湪澶勭悊鏃ユ湡鍜屾椂闂寸被鍨嬬殑鍊兼椂锛孧ySQL甯︽湁5涓笉...
绛旓細MySQL鏁版嵁绫诲瀷鏈 鏁存暟绫诲瀷锛欱IT銆丅OOL銆乀INY INT銆丼MALL INT銆丮EDIUM INT銆 INT銆 BIG INT 娴偣鏁扮被鍨嬶細FLOAT銆丏OUBLE銆丏ECIMAL 瀛楃涓茬被鍨锛欳HAR銆乂ARCHAR銆乀INY TEXT銆乀EXT銆丮EDIUM TEXT銆丩ONGTEXT銆乀INY BLOB銆丅LOB銆丮EDIUM BLOB銆丩ONG BLOB 鏃ユ湡绫诲瀷锛欴ate銆丏ateTime銆乀imeStamp銆乀ime銆乊ear 鍏朵粬鏁版嵁绫诲瀷...
绛旓細Mysql鏀寔鐨勫绉嶆暟鎹被鍨嬩富瑕佹湁锛氭暟鍊兼暟鎹被鍨嬨佹棩鏈/鏃堕棿绫诲瀷銆佸瓧绗︿覆绫诲瀷銆 1.鏁存暟鏁版嵁绫诲瀷鍙婂叾鍙栧艰寖鍥达細绫诲瀷 璇存槑 瀛樺偍闇姹傦紙鍙栧艰寖鍥达級tinyint 寰堝皬鏁存暟 1瀛楄妭锛圼0~255]銆乕-128~127]锛; 255=2^8-1;127=2^7-1 smallint 灏忔暣鏁 2瀛楄妭锛0~65535銆-32768~32767锛 ;65535=2^16...
绛旓細MySQL鏁版嵁搴绫诲瀷涓昏鏈変互涓嬪嚑绉嶏細1. MyISAM瀛樺偍寮曟搸锛氳繖鏄MySQL鐨榛樿瀛樺偍寮曟搸涔嬩竴锛屼富瑕佺敤浜庨潪浜嬪姟鎬鐨勬暟鎹搴撳簲鐢ㄣ傚畠鎻愪緵浜嗚緝楂樼殑璇诲彇閫熷害锛屼絾鍐欐搷浣滅浉瀵硅緝鎱侻yISAM涓嶆敮鎸佷簨鍔″鐞嗭紝涔熶笉鏀寔琛岀骇閿佸畾銆備笉杩囷紝瀹冩敮鎸佸叏鏂囩储寮曪紝瀵逛簬鏂囨湰鎼滅储搴旂敤寰堟湁鐢ㄣ傞殢鐫MySQL鐨勫彂灞曪紝璁稿鐢ㄦ埛宸茬粡寮濮嬭浆鍚戞洿寮哄ぇ鐨...
绛旓細璇存槑锛氬拰Enum绫诲瀷绫讳技锛岄噷闈㈠彲浠ヤ繚瀛0~64涓垚鍛樸傚拰Enum绫诲瀷鏈澶х殑鍖哄埆鏄細SET绫诲瀷涓娆″彲浠ラ夊彇澶氫釜鎴愬憳锛岃孍num鍙兘閫変竴涓 鏍规嵁鎴愬憳涓暟涓嶅悓锛屽瓨鍌ㄦ墍鍗犵殑瀛楄妭涔熶笉鍚 锛1锛塗imestamp鏀寔鐨勬椂闂磋寖鍥磋緝灏忥紝鍙栧艰寖鍥达細 1970-01-01-08:00:01鈥斺2038骞寸殑鏌愪釜鏃堕棿 Datetime鐨勫彇鍊艰寖鍥达細1000-1-1 鈥...
绛旓細MySQL 鏁版嵁绫诲瀷缁嗗垎涓嬫潵,澶ф鏈変互涓嬪嚑绫: 鏁板,鍏稿瀷浠h〃涓 tinyint,int,bigint 娴偣/瀹氱偣,鍏稿瀷浠h〃涓 float,double,decimal 浠ュ強鐩稿叧鐨勫悓涔夎瘝 瀛楃涓,鍏稿瀷浠h〃涓 char,varchar 鏃堕棿鏃ユ湡,鍏稿瀷浠h〃涓 date,datetime,time,timestamp 浜岃繘鍒,鍏稿瀷浠h〃涓 binary,varbinary 浣嶇被鍨 鏋氫妇绫诲瀷 闆嗗悎绫诲瀷 澶у璞,姣斿 text,blo...
绛旓細MySQL 鏁版嵁绫诲瀷缁嗗垎涓嬫潵锛屽ぇ姒傛湁浠ヤ笅鍑犵被锛氭暟鍊硷紝鍏稿瀷浠h〃涓 tinyint,int,bigint娴偣/瀹氱偣锛屽吀鍨嬩唬琛ㄤ负 float,double,decimal 浠ュ強鐩稿叧鐨勫悓涔夎瘝瀛楃涓诧紝鍏稿瀷浠h〃涓 char,varchar鏃堕棿鏃ユ湡锛屽吀鍨嬩唬琛ㄤ负 date,datetime,time,timestamp浜岃繘鍒讹紝鍏稿瀷浠h〃涓 binary,varbinary浣嶇被鍨嬫灇涓剧被鍨嬮泦鍚堢被鍨 ...
绛旓細M 鎸囧嚭鏈澶х殑鏄剧ず灏哄銆傛渶澶х殑鍚堟硶鐨勬樉绀哄昂瀵告槸 255 銆侱 閫傜敤浜庢诞鐐圭被鍨嬪苟涓旀寚鍑鸿窡闅忓湪鍗佽繘鍒跺皬鏁扮偣鍚庣殑鏁扮爜鐨勬暟閲忋傛渶澶у彲鑳界殑鍊兼槸30锛屼絾鏄簲璇ヤ笉澶т簬M-2銆傛柟鎷彿(鈥淸鈥濆拰鈥淽鈥)鎸囧嚭鍙鐨勭被鍨淇グ绗︾殑閮ㄥ垎銆傛敞鎰忥紝濡傛灉浣犳寚瀹氫竴涓簡涓篫EROFILL锛MySQL灏嗕负璇ュ垪鑷姩鍦板鍔燯NSIGNED灞炴с俆INYINT[(M...