Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Difference in MySQL VARCHAR and CHAR data format     - The first deployment of cross-platform operation Rafy record (Server)

- To solve the Mac in question invalid BASH under configuration environment variable (Linux)

- Approach the next Linux shared interrupts (Linux)

- Struts2 study notes -Valuestack (value stack) and OGNL expression (Programming)

- Oracle ORA-01691 error message, a single data file size limit problem (Database)

- Windows and Ubuntu dual system, repair of two ways UEFI boot (Linux)

- The correct method to modify the maximum number of concurrent connections Tomcat 7 (Server)

- Spring declarative transaction management (Programming)

- Linux configuration startup mount: fstab file (Linux)

- Installation and use Docker under Ubuntu 14.04 (Linux)

- ssh port forwarding Comments (Server)

- Configuring Haproxy log support (syslog logging support) (Server)

- How to protect your eyes automatically adjust the screen brightness on Linux (Linux)

- Fedora 22 how to play rmvb mp4 mkv video files (Linux)

- Through the source code to install MySQL 5.6.26 under CentOS6 (Database)

- Oracle 11g maintenance partitions (Seven) - Modifying Real Attributes of Partitions (Database)

- MongoDB common optimization settings in Linux (Database)

- Linux formatted partition error Could not stat / dev / sda No such file or directory Solution (Linux)

- Configuring a Linux operating system security management services Explain (Linux)

- Apache Mina framework Practice (Programming)

 
         
  Difference in MySQL VARCHAR and CHAR data format
     
  Add Date : 2018-11-21      
         
       
         
  The difference

Similar to VARCHAR CHAR type, but a different way to save and retrieve them. CHAR fixed length, while VARCHAR belong to a variable-length character type. Their maximum length and whether trailing spaces are retained, it is also different. In the storage and retrieval process does not perform case conversion.

The following table shows the various string values ​​are saved to CHAR (4) and VARCHAR (4) The results are shown after the description of the differences between CHAR and VARCHAR:

Value CHAR (4) storage requirements VARCHAR (4) storage requirements
'' '' Four-byte 'byte 1
'Ab' 'ab' 4 bytes 'ab' 3 bytes
'Abcd' 'abcd' 4 bytes 'abcd' 5 bytes
'Abcdefgh' 'abcd' 4 bytes 'abcd' 5 bytes
From the above you can see that CHAR is fixed length, regardless of the data you store is how much he would have a fixed length. While at the VARCHAR variable length but he wants to increase the total length of 1 byte, which is used to store characters in length (if the length of the statement exceeds 255, use two bytes). So the actual application user can do according to their data type.

Note that the value in the last row in the table apply only when not using strict mode; if MySQL is running in strict mode, over the length of the column value is not saved, and you receive an error.

From CHAR (4) and VARCHAR (4) columns retrieved values ​​are not always the same, because when retrieving deleted trailing spaces from CHAR columns. Explained by differences in the following example:

mysql> CREATE TABLE test (a VARCHAR (4), b CHAR (4));
mysql> INSERT INTO test VALUES ( 'ab', 'ab');
mysql> SELECT CONCAT (a, '+'), CONCAT (b, '+') FROM test;
The results are as follows:

CONCAT (a, '+') CONCAT (b, '+')
ab + ab +
From the above it can be seen, for some reason CHAR have a fixed length, than in the processing speed is much faster VARCHAR, but the relative waste of storage space, so storage is not big, but the speed requirements can use the CHAR type, Conversely VARCHAR type can be achieved.
Suggest

MyISAM storage engine is recommended to use a fixed length data column instead of the variable length data columns
INNODB storage engine type recommended VARCHAR
     
         
       
         
  More:      
 
- Linux --- process tracking (Linux)
- Tsung first test installation (Linux)
- CentOS 6.5 install Maven and Nexus warehouse agent (Server)
- History and Statistics tuptime use tools to view Linux server system boot time (Server)
- C # Future: Method Contract (Programming)
- Linux use glibc2 library and crypt () function to generate the user password (Programming)
- Overall Physical Migration of Oracle Database with (Database)
- Java memory-mapped file MappedByteBuffer (Programming)
- Oracle delete table space prompted ORA-00604 and ORA-38301 (Database)
- Computer security protection remove local and remote system log files (Linux)
- C ++ casts New Standard Comments (Programming)
- Hadoop - Task Scheduling System Comparison (Server)
- Ten SCP transfer command example (Linux)
- Seven kinds of NIC binding mode Detail (Linux)
- How to understand the difference between synchronous and asynchronous non-blocking blocking (Programming)
- Linux commands with browsing and downloading files (Linux)
- CentOS 6.5_x64 install Oracle 11g R2 (Database)
- Linux screen command (Linux)
- WordPress blog installation Redis Cache (Server)
- Linux Shell Scripting (Programming)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.