当前位置:网站首页>The problem of returning the longtext field in MySQL and its solution
The problem of returning the longtext field in MySQL and its solution
2022-07-05 19:13:00 【1024 questions】
MySql in longtext Field return
As shown in the figure below
resolvent
Mysql in Text The range of the field
Chinese characters are in utf8mb4 Take up a few characters in
MySql in longtext Field returnIn recent development longtext This kind of field . stay mysql The maximum length of this field in is 4G
As shown in the figure belowOne of the problems encountered in development is . For example, there is a article surface , Then our page will show the data to the front end in the form of a list ( Only a few fields are displayed , As the author , Title and so on , For example, put table Multiple records are displayed in ), But it is to find out all the information in the table , Then when the user clicks on a record , Will jump to the details page , The detailed information is displayed .
In this way, when there is a large amount of data , Or when the content of the text is relatively large , There's a problem .
Open the page , The page will always load , More data , The longer the loading time , Then the data list will be displayed . This will seriously affect the use effect .
resolventCertainly sql Sentence problem , When querying the whole list like the above , Can not query longtext This field , Query other fields . Then when the user clicks on a piece of data , Then according to the data id Go to the database to check this data , At this time, we will longtext Just find out .
Speaking of this , There is also a situation , Sometimes the data found in the database is encapsulated into entity classes , You can never get the value of a field , Namely null. At this time, I want to see sql sentence , Whether the returned result set encapsulates and maps this field to the corresponding field of this class .
Generally, the reason why this field is not encapsulated in the result set .
Mysql in Text The range of the fieldtext: Store variable length non Unicode data , Maximum length is 2^31-1 Characters .
text Column cannot have default value , During storage or retrieval , There is no case conversion , If the length is specified , No mistakes will be reported , But this length doesn't work , That means when you insert data , If it exceeds the length you specified, it can be inserted normally .
mysql in text Maximum length is 65,535(2 Of 16 Power –1) Character TEXT Column .
If you think text Not long enough , You can choose
MEDIUMTEXT
Maximum length is 16,777,215.
LONGTEXT
Maximum length is 4,294,967,295
Text
It is mainly used to store non binary text , Such as forum posts , subject , Or Baidu knows the questions and answers .
What needs to be clear is text and char varchar blob The differences between these types .
mysql modify text Field length _mysql Of text Field length ?mysql In the database text Insufficient field length …
The type is a variable length string , most 65535 Characters ;
You can change the field type to MEDIUMTEXT( At most 16777215 Characters ) perhaps LONGTEXT( At most 4294967295 Characters ).
Chinese characters are in utf8mb4 Take up a few characters inMySQL supports 4 TEXT field types (TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT) and this post looks at the maximum length of each of these field types.
MyISAM tables in MySQL have a maximum size of a row of 65,535 bytes, so all the data in a row must fit within that limit. However, the TEXT types are stored outside the table itself and only contribute 9 to 12 bytes towards that limit. (For more information about this refer to the MySQL Manual - Data Storage Requirements chapter). TEXT data types are also able to store much more data than VARCHAR and CHAR text types so TEXT types are what you need to use when storing web page or similar content in a database. The maximum amount of data that can be stored in each data type is as follows: TINYTEXT256 bytes
TEXT65,535 bytes~64kb
MEDIUMTEXT 16,777,215 bytes~16MB
LONGTEXT4,294,967,295 bytes~4GB
In most circumstances the TEXT type is probably sufficient, but if you are coding a content management system it’s probably best to use the MEDIUMTEXT type for longer pages to ensure there are no issues with data size limits.
answer :3 individual
MySQL For utf8mb4 The explanation is
The existing database version defaults to utf8 All for utf8mb3, Pay attention to what it says " Same length ".
So in utf8mb4 Next , English occupation 1 Bytes , General Chinese characters account for 3 Bytes ,emoji Account for expression 4 Bytes .
About code insertion emoji Expression error , Please check Table code and Database connection Whether the code is utf8mb4.
Conclusion : Both database and table are set to utf8mb4.
The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .
边栏推荐
- Go语言 | 02 for循环及常用函数的使用
- Is it safe for China Galaxy Securities to open an account? Securities account opening
- Go deep into the underlying C source code and explain the core design principles of redis
- Startup and shutdown of CDB instances
- Hiengine: comparable to the local cloud native memory database engine
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验8 定时器中断实验(学习笔记)
- Blue sky drawing bed Apple quick instructions
- Fundamentals of machine learning (III) -- KNN / naive Bayes / cross validation / grid search
- R language Visual scatter plot graph, add labels to some data points in the graph, and always display all labels, even if they have too much overlap. Ggrep package helps
- cf:B. Almost Ternary Matrix【對稱 + 找規律 + 構造 + 我是構造垃圾】
猜你喜欢
HiEngine:可媲美本地的云原生内存数据库引擎
How to quickly advance automated testing? Listen to the personal feelings of the three bat test engineers
Tupu software digital twin | visual management system based on BIM Technology
cf:B. Almost Ternary Matrix【对称 + 找规律 + 构造 + 我是构造垃圾】
5. Data access - entityframework integration
MySql中的longtext字段的返回问题及解决
Mysql如何对json数据进行查询及修改
跨境支付平台 XTransfer 的低代码实践:如何与其他中台融合是核心
The era of Web3.0 is coming. See how Tianyi cloud storage resources revitalize the system to enable new infrastructure (Part 2)
Go deep into the underlying C source code and explain the core design principles of redis
随机推荐
The monthly list of Tencent cloud developer community videos was released in May 2022
XML basic knowledge concept
2022 the latest big company Android interview real problem analysis, Android development will be able to technology
Talking about fake demand from takeout order
R language Visual scatter plot graph, add labels to some data points in the graph, and always display all labels, even if they have too much overlap. Ggrep package helps
Go语言 | 03 数组、指针、切片用法
MySQL数据库索引教程(超详细)
如何实现游戏中的在线计时器和离线计时器
数据库 逻辑处理功能
如何快速进阶自动化测试?听听这3位BAT大厂测试工程师的切身感想....
Tianyi cloud understands enterprise level data security in this way
Benefits of automated testing
跨境支付平台 XTransfer 的低代码实践:如何与其他中台融合是核心
The era of Web3.0 is coming. See how Tianyi cloud storage resources revitalize the system to enable new infrastructure (Part 2)
Django使用mysqlclient服务连接并写入数据库的操作过程
为什么 BI 软件都搞不定关联分析?带你分析分析
shell编程基础(第9篇:循环)
China law network joins hands to observe the cloud, and the online system is a full link observable platform
开源 SPL 消灭数以万计的数据库中间表
UDF implementation of Dameng database