Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Database \ Difference in MySQL VARCHAR and CHAR data format     - Close and limit unused ports computer server security protection (Linux)

- Ubuntu 15.10 15.04 14.10 14.04 Install Ubuntu Tweak (Linux)

- PHP interview questions of design patterns (Programming)

- Oracle capability i / o (stress test database server i / o performance) (Database)

- Linux modify the network interface name (Linux)

- Linux Nginx installation and configuration instructions (Server)

- Use innobackupex full realization of MySQL hot backup (Database)

- Java NIO The Glob mode Detailed (Programming)

- Linux Security Setup Guide (Linux)

- redis configuration in detail (English) (Database)

- PL / SQL how to make the program every few seconds to insert a data (Database)

- crontab task scheduling Health Check (Linux)

- CentOS 6.2 install git error Perl5 (Linux)

- Four levels of intrusion on Linux server and counter-measures (Linux)

- Ubuntu Tutorial: How to Upgrade a New Linux Kernel 3.12.7 on Ubuntu (Linux)

- Oracle PL / SQL selective basis (IF CASE), (LOOP WHILE FOR) (Database)

- Ubuntu 12.04 installation NVIDIA GTX750 graphics driver (Linux)

- Management and application Oracle external table (Database)

- Hadoop namenode do NFS disaster recovery (Server)

- SSH automatic disconnection problem solving (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
- C ++ class implementation date operator overloading (Programming)
- CentOS use wget (Linux)
- Correlation Analysis: FP-Growth algorithm (Programming)
- How to enhance the security of Linux systems (Linux)
- MySQL Study of --Percona Server 5.5 Upgrade 5.6 (Database)
- Teach you how to protect the Linux operating system security tips (Linux)
- Squid proxy server (Server)
- RegExp object implements regular match --JavaScript (Programming)
- Zabbix configure DataGuard monitoring (Database)
- GitLab upgrade to 8.2.0 (Linux)
- Linux file permissions bit forced bits and adventure Comments (Linux)
- Linux server security - the web server configuration (Linux)
- MySQL service failed to start thinking of settlement under CentOS7 (Database)
- To install Git on Ubuntu systems (Server)
- Debian SSD ext4 4K aligned (Linux)
- MySQL In can not be overridden with an internal connection (Database)
- MySQL management partition table (Database)
- MySQL Statistics (Database)
- Linux shell script under the use of randomly generated passwords (Programming)
- On the PC goes heavy security watch your startup items (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.