How to calculate the length of data by mysql
Editor to share with you mysql how to find the length of the data, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Mysql data length method: 1, use the "LENGTH" function to get the string length, syntax such as "SELECT LENGTH ('character')"; 2, through the "CHAR_LENGTH" function to view the string length, syntax such as "SELECT CHAR_LENGTH ('character')".
MySql calculates the length of the field
User account has useful Chinese characters. Find all accounts that contain Chinese characters.
SELECT member_name FROM table_member WHERE length (member_name)! = char_length (member_name) LENGTH
The "LENGTH" function in mysql is a built-in function to get the length of a string.
CHAR_LENGTH
Another function that looks at the string length in the mysql built-in function is "CHAR_LENGTH". The difference between the two functions is:
LENGTH: a Chinese character is counted as three characters, and a number or letter as a character.
CHAR_LENGTH: whether a Chinese character or a number or a letter is a character
Example
Chinese characters
SELECT LENGTH ('character'); output: 6SELECT CHAR_LENGTH ('character'); output: 2
Character
SELECT LENGTH ('abc'); output: 3SELECT CHAR_LENGTH (' abc'); output: 3 command units, one Chinese character, one numeric or letter example char_length character 11char_length (str) lengthByte31length (str) bit_lengthbit248length (str)
When the length of the string exceeds the maximum length defined by max_allowed_packet, the above function returns NULL.
Max_allowed_packet generally defaults to 4MB (5.6.5 and below is 1MB)
These are all the contents of how mysql calculates the length of the data. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!