NULL and Empty String in Mysql

NULL and Empty String in Mysql

I recently came into contact with MySQL. Yesterday I created a new table to store table structure information:

create table tablist(TABLE_SCHEMA varchar(40),TABLE_NAME varchar(40),COLUMN_NAME varchar(40),COLUMN_TYPE varchar(40),
IS_NULLABLE varchar(10),COLUMN_DEFAULT varchar(40),COLUMN_COMMENT varchar(1000),REMARK varchar(2000));
insert into tablist(TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT,COLUMN_COMMENT)
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT,COLUMN_COMMENT
from information_schema.`COLUMNS` where TABLE_SCHEMA='leo';

Then query the tablist table:

See which columns have no comments:

select * from tablist where COLUMN_COMMENT is null;

The result I found was Empty set. However, from the above query results and Navicat, we can see that the null value is displayed as the word 'null' in the result set, while the empty string is displayed as empty.

After checking the information, I found that there is a difference between the null value and the empty string in Mysql. It is very strange that after the COLUMN_COMMENT is inserted, the null value turns into an empty string (the reason is unknown).

Use select * from tablist where COLUMN_COMMENT=''; and the query works fine.

NULL columns require additional space in the row to record whether their values ​​are NULL. For MyISAM tables, each NULL column takes one bit extra, rounded up to the nearest byte.

In MySQL's myisam engine, null values ​​take up additional storage space (1 bit), while empty strings take up no space at all. At the same time, null values ​​cannot be stored in B-tree indexes, which will cause serious performance problems when the amount of data is large.

The query methods of the two are also different: null value query uses is null/is not null query, while empty string can be queried using = or !=.

Summarize

The above is what I introduced to you about NULL and Empty String in Mysql. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • The MySQL server is running with the --read-only option so it cannot execute this statement
  • mysql databasemysql: [ERROR] unknown option ''--skip-grant-tables''
  • Detailed explanation of ensuring the consistency of MySQL views (with check option)
  • Solution to the error message "java.sql.SQLException: Incorrect string value:'\xF0\x9F\x92\xA9\x0D\x0A...'" when storing emoticons in MySQL
  • An example of connecting mysql with php via odbc to any database
  • Detailed explanation of installing and completely uninstalling mysql with apt-get under Ubuntu
  • Examples of the correct way to use AES_ENCRYPT() and AES_DECRYPT() to encrypt and decrypt MySQL
  • mysql server is running with the --skip-grant-tables option
  • Detailed explanation of using pt-heartbeat to monitor MySQL replication delay
  • Introduction to the use of MySQL pt-slave-restart tool

<<:  Top 10 Js Image Processing Libraries

>>:  How to transfer files between Windows and Linux

Recommend

202 Free High Quality XHTML Templates (1)

Here 123WORDPRESS.COM presents the first part of ...

Detailed explanation of vite2.0 configuration learning (typescript version)

introduce You Yuxi’s original words. vite is simi...

Implementation of ssh non-secret communication in linux

What is ssh Administrators can log in remotely to...

Summary of common optimization operations of MySQL database (experience sharing)

Preface For a data-centric application, the quali...

How to configure CDN scheduling using Nginx_geo module

Introducing the Geo module of Nginx The geo direc...

Solution to MySQL replication failure caused by disk fullness

Table of contents Case scenario Solving the probl...

How to implement one-click deployment of nfs in linux

Server Information Management server: m01 172.16....

Experience in designing a layered interface in web design

Many netizens often ask why their websites always ...

Play and save WeChat public account recording files (convert amr files to mp3)

Table of contents Audio transcoding tools princip...

How to use javascript to do simple algorithms

Table of contents 1 Question 2 Methods 3 Experime...

In-depth explanation of the locking mechanism in MySQL

Preface In order to ensure the consistency and in...

MySQL database Load Data multiple uses

Table of contents Multiple uses of MySQL Load Dat...

Summary of common commands for Linux user and group management

This article summarizes the common commands for L...