日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql最大述_mysql最大字段数量及 varchar类型总结

發布時間:2024/10/8 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql最大述_mysql最大字段数量及 varchar类型总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

mysql最大字段數

一直對mysql最大字段數不明確有人說是1024

還有人說

Max columns per row 4096

InnoDB is limited to 1000columns

實踐是檢驗真理的唯一方法

mysql> use test;

mysql> create table t0008(id int) engine=innodb DEFAULT CHARSET=latin1;

[root@localhost ~]# vim add.sh

#/bin/bash

num=2

while((num<2000))

do

echo $num

mysql -p123456 -D test -e "alter table t0008 add column(col$num char(1))"

num=$(($num+1))

done

[root@localhost ~]# ./add.sh

Warning: Using a password on the command line interface can be insecure.

1017

Warning: Using a password on the command line interface can be insecure.

1018

Warning: Using a password on the command line interface can be insecure.

ERROR 1117 (HY000) at line 1: Too many columns

mysql> desc t0008;

+---------+------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+---------+------------+------+-----+---------+-------+

| id | int(11) | YES | | NULL | |

| col2 | varchar(1) | YES | | NULL | |

| col3 | varchar(1) | YES | | NULL | |

...............................................................................

...............................................................................

| col1014 | varchar(1) | YES | | NULL | |

| col1015 | varchar(1) | YES | | NULL | |

| col1016 | varchar(1) | YES | | NULL | |

| col1017 | varchar(1) | YES | | NULL | |

+---------+------------+------+-----+---------+-------+

1017 rows in set (0.01 sec)

mysql innodb引擎支持最大字段上線為1017

mysql> create table t0011(col1 char(1)) engine=myisam DEFAULT CHARSET=latin1;

Query OK, 0 rows affected (0.00 sec)

[root@localhost ~]# ./add.sh

Warning: Using a password on the command line interface can be insecure.

2410

Warning: Using a password on the command line interface can be insecure.

2411

Warning: Using a password on the command line interface can be insecure.

ERROR 1117 (HY000) at line 1: Too many columns

2412

Warning: Using a password on the command line interface can be insecure.

ERROR 1117 (HY000) at line 1: Too many columns

mysql> desc t0011;

+---------+---------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+---------+---------+------+-----+---------+-------+

| col1 | char(1) | YES | | NULL | |

| col2 | char(1) | YES | | NULL | |

| col3 | char(1) | YES | | NULL | |

.........................................................................

........................................................................

| col2408 | char(1) | YES | | NULL | |

| col2409 | char(1) | YES | | NULL | |

| col2410 | char(1) | YES | | NULL | |

+---------+---------+------+-----+---------+-------+

2410 rows in set (0.04 sec)

mysql myisam引擎最大字段上限為2410

-----------------------------------------------------------------------------------------------------------------

varchar字段的長度

mysql> create table t0008(col1 varchar(65535))charset=latin1;

ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

mysql> create table t0008(col1 varchar(65534))charset=latin1;

ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

mysql> create table t0008(col1 varchar(65533))charset=latin1;

ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

mysql> create table t0008(col1 varchar(65532))charset=latin1;

Query OK, 0 rows affected (0.02 sec)

latin1字符集下的表varchar上限為65532,即一個字符一個字節

mysql> create table t0009(col1 varchar(65533))charset=utf8;

ERROR 1074 (42000): Column length too big for column "col1" (max = 21845); use BLOB or TEXT instead

mysql> create table t0009(col1 varchar(21845))charset=utf8;

ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

mysql> create table t0009(col1 varchar(21844))charset=utf8;

Query OK, 0 rows affected (0.00 sec)

utf8字符集下的表varchar上限為21844,即一個字符三個字節 65535-1-2 結果除以3 ==21844

-1表示第一個字節不存數據,-2表示兩個字節存放varchar的長度,除以3是utf8字符特性,一個字符三個字節。

varchar 字段是將實際內容單獨存儲在聚簇索引之外,內容開頭用1到2個字節表示實際長度(長度超過255時需要2個字節),因此最大長度不能超過65535即 2的16次方(0-65535)

mysql> create table t0012(id int,name char(20),col3 varchar(N))chaset=utf8;

N的值為:(65535-1-2-4-20*3)/3=21822

mysql> create table t0012(id int,name char(20),col3 varchar(N))charset=latin1;

N的值為:65535-1-2-4-20=65508

char_length:在任何編碼下, 不管漢字還是數字或者是字母都算是一個字符

length: 是計算字段的長度, utf8編碼下,一個漢字是算三個字符,一個數字或字母算一個字符。其他編碼下,一個漢字算兩個字符, 一個數字或字母算一個字符。 CHARACTER_LENGTH(str) CHARACTER_LENGTH()是CHAR_LENGTH()的同義詞。 BIT_LENGTH(str) 返回2進制長度

MySQL數據類型(留作備忘)

類 型

大 小

描 述

CAHR(Length)

Length字節

定長字段,長度為0~255個字符

VARCHAR(Length)

String長度+1字節或String長度+2字節

變長字段,長度為0~65 535個字符

TINYTEXT

String長度+1字節

字符串,最大長度為255個字符

TEXT

String長度+2字節

字符串,最大長度為65 535個字符

MEDIUMINT

String長度+3字節

字符串,最大長度為16 777 215個字符

LONGTEXT

String長度+4字節

字符串,最大長度為4 294 967 295個字符

TINYINT(Length)

1字節

范圍:-128~127,或者0~255(無符號)

SMALLINT(Length)

2字節

范圍:-32 768~32 767,或者0~65 535(無符號)

MEDIUMINT(Length)

3字節

范圍:-8 388 608~8 388 607,或者0~16 777 215(無符號)

INT(Length)

4字節

范圍:-2 147 483 648~2 147 483 647,或者0~4 294 967 295(無符號)

BIGINT(Length)

8字節

范圍:-9 223 372 036 854 775 808~9 223 372 036 854 775 807,或者0~18 446 744 073 709 551 615(無符號)

FLOAT(Length, Decimals)

4字節

具有浮動小數點的較小的數

DOUBLE(Length, Decimals)

8字節

具有浮動小數點的較大的數

DECIMAL(Length, Decimals)

Length+1字節或Length+2字節

存儲為字符串的DOUBLE,允許固定的小數點

DATE

3字節

采用YYYY-MM-DD格式

DATETIME

8字節

采用YYYY-MM-DD HH:MM:SS格式

TIMESTAMP

4字節

采用YYYYMMDDHHMMSS格式;可接受的范圍終止于2037年

TIME

3字節

采用HH:MM:SS格式

ENUM

1或2字節

Enumeration(枚舉)的簡寫,這意味著每一列都可以具有多個可能的值之一

SET

1、2、3、4或8字節

與ENUM一樣,只不過每一列都可以具有多個可能的值

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的mysql最大述_mysql最大字段数量及 varchar类型总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。