Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Database \ Difference in MySQL VARCHAR and CHAR data format     - Linux systems use IP masquerading anti-hacker (Linux)

- Generated characters using Java Videos (Programming)

- Using 30 seconds to write a detailed analysis of garbage removal system (Linux)

- How to fix fatal error: security / pam_modules.h: No such file or directory (Linux)

- Android Dynamic efficiency articles: a brilliant Loading Analysis and Implementation (Programming)

- CentOS / Linux SWAP partitions added (Linux)

- To compiler and install MariaDB-10.0.20 under CentOS 6.6 (Database)

- to install the deployment of LVS under CentOS 7.0 (Server)

- JavaScript is implemented without new keywords constructor (Programming)

- Java polymorphism and exception handling (Programming)

- Security Knowledge: redirection command application security (Linux)

- Linux (SUSE) mount NTFS mobile hard practice (Linux)

- In-depth summary of the PHP core of object-oriented (Programming)

- Timing Nginx logs cut and remove the log records of the specified number of days before (Server)

- Install Ubuntu 14.04 and Windows 8 / 8.1 dual-boot in UEFI mode (Linux)

- Ubuntu method for single-card dual-IP (Linux)

- To disable the function by pressing Ctrl-Alt-Del to restart the system in RHEL / CentOS 5/6 (Linux)

- Python Dir find a folder several files (Programming)

- Oracle query start with connect by tree (Database)

- Linux based exercises, interview questions (Linux)

  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.

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
- Using Linux / Unix Text processing (Linux)
- PostgreSQL 9.3.2 Json type of use (Database)
- CentOS7 iptables (Linux)
- Zabbix monitoring different versions of RAID installation and monitoring and MySQL master-slave monitor (Server)
- RHEL7.0 environment Linux kernel upgrade (Linux)
- Java8 Lambda expressions and flow operations (Programming)
- numpy and SciPy installation under Python for scientific computing package (Linux)
- Spark parquet merge metadata problem (Server)
- Linux Proc File System Experiment (Linux)
- A simple shell script for monitoring in Linux (Linux)
- Java Concurrency - multiple threads of HelloWorld (Programming)
- About Auto Layout and frame (Programming)
- CentOS 6.6 installation certification system based on the ftp service (Server)
- CentOS6 5 source compiler installation Hadoop2.5.1 (Server)
- Physical backup and recovery SYSTEM table space (Database)
- Swift acquaintance of values and references, the circular reference, Agent Precautions (Programming)
- The new task parallel library feature in .NET 4.6 (Programming)
- C ++ why we chose to use the smart pointer (Programming)
- How Glances monitoring system on Ubuntu (Linux)
- OpenJDK7 source compiler installation on CentOS 6.5 (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.