Home > Database > Mysql Tutorial > How does MySQL react when we specify the CHARACTER SET binary attribute for a string data type?

How does MySQL react when we specify the CHARACTER SET binary attribute for a string data type?

王林
Release: 2023-09-09 13:57:02
forward
1026 people have browsed it

当我们为字符串数据类型指定 CHARACTER SET 二进制属性时,MySQL 如何反应?

On specifying a CHARACTER SET binary attribute for a character string data type, MySQL creates that column as its subsequent binary string type. The conversions for CHAR, VARCHAR and BLOB data types take place as follows −

  • CHAR would become BINARY
  • VARCHAR would become VARBINARY
  • TEXT would become BLOB

The above kind of conversion does not occur for ENUM and SET data type and they both are created as declared while creating the table.

Example

In the example below we have created a table named ‘EMP’ with four columns all specified as CHARACTER SET binary as follows −

mysql> Create table Emp(Name varchar(10) CHARACTER SET binary, Address CHAR(10)CHARACTER SET binary, Designation TEXT CHARACTER SET binary, Field ENUM('ENG','SS') CHARACTER SET binary);
Query OK, 0 rows affected (0.16 sec)
Copy after login

But now on checking the status of table, with the help of query below, we can see that MySQL has changed the data type according to its subsequent binary string.

mysql> Show Create Table EMP\G
*************************** 1. row ***************************
      Table: EMP
Create Table: CREATE TABLE `emp` (
   `Name` varbinary(10) DEFAULT NULL,
   `Address` binary(10) DEFAULT NULL,
   `Designation` blob,
   `Field` enum('ENG','SS') CHARACTER SET binary DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of How does MySQL react when we specify the CHARACTER SET binary attribute for a string data type?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template