MySQL table mysteriously disappears after being created? Uncovering the zero-width character trap

Three tips to teach you how to solve the zero-width character trap and make your database no longer "haunted".

Author: Qin Fulang, a member of the DBA team of Aikesheng, responsible for handling daily project problems and troubleshooting company platform problems. A DBA who loves the Internet, knows photography, and knows cooking skills is not a good driver, didi~

Produced by the Aikeson open source community, original content may not be used without authorization. Please contact the editor and indicate the source for reprinting.

This article is about 1,000 words and is expected to take 3 minutes to read.

introduction

In the process of using MySQL, sometimes a small character can cause big trouble. Before discovering the truth, I thought the problem was caused by a ghost. But when I discovered the truth, I didn't expect that it was caused by a single character. The problem is that zero-width characters are like a ghost hidden in all aspects of the IT industry. Today I will share a recurring case of "disappearing tables" in MySQL.

Problem Description

testA table named is created in the database through some means (such as command line or database development tools, etc.) lang. The table structure is as follows:

CREATE TABLE `lang​` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键自增',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Through SHOW TABLES;the command, we can confirm the existence of this table.

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| a1             |
| lang​          |
| t1             |
| z1             |
+----------------+
4 rows in set (0.00 sec)

However, when you try to execute a query or business program on the MySQL client SELECT * FROM lang;to connect to the table, you receive an error message:

mysql> select * from lang;
ERROR 1146 (42S02): Table 'test.lang' doesn't exist

The watch just magically disappeared.

Cause Analysis

It's like seeing a ghost. Even if you manually enter the query syntax many times, you can't query this table. We copy the table creation statement into the Sublime Text text tool:

At this time, we discovered the problem: the table name was followed by a character "<0×200b>". This is a zero-width space, which is a type of zero-width character.

What are zero-width characters?

A zero-width character is a special Unicode character that does not take up any visible space and is therefore invisible in most situations. However, they can exist in text and may have an impact on computer programs, including database management systems. In Unicode, U+200B stands for zero-width space and is often used where line breaks may be needed. In addition, there are other zero-width characters, which will not be described here.

So why does this ghost-like character exist? The so-called existence means reasonable. Zero-width characters are often used in scenarios such as data anti-crawling, encrypted information transmission, and prevention of sensitive word scanning. But when used in a database system, sometimes there will be headaches, and the one mentioned in this article is one of them. Although these characters do not take up any space, they may destroy the correct structure of the SQL command and cause errors in subsequent uses.

How to solve?

  1. Before creating a table, copy the table creation statement to multiple text editing tools and check whether there are any abnormal symbol prompts (general text tools may not be able to display zero-width characters). After trying tools or plug-ins such as Sublime Text and Visual Studio Code, they have the function of reminding zero-width characters; there are also some online web tools that can view Unicode characters. If you know of other tools that can display zero-width characters, please leave a message in the comment area to share.
  2. After creating the table, use SHOW CREATE TABLE;the command to view the table structure, and then copy the output to the above text editing tool to check whether there are any abnormal symbols.
  3. After many tests, it was found that when the command was executed on the MySQL client , the border line "|"SHOW TABLES; behind the table name containing zero-width spaces was not aligned with other lines. This allows quick discovery of problematic tables, but does not display specific characters. Of course, this method generally does not apply to third-party development tools, business programs, etc.

Summarize

Zero-width characters are an invisible trap that may cause some seemingly unsolvable problems during the use of MySQL. By understanding their nature, double-checking SQL commands, avoiding copying and pasting from unreliable sources, using appropriate tools, and following best practices, we can ensure that our database runs smoothly and no similar issues arise.

For more technical articles, please visit: https://opensource.actionsky.com/

About SQLE

SQLE is a comprehensive SQL quality management platform that covers SQL auditing and management from development to production environments. It supports mainstream open source, commercial, and domestic databases, provides process automation capabilities for development and operation and maintenance, improves online efficiency, and improves data quality.

SQLE get

type address
Repository https://github.com/actiontech/sqle
document https://actiontech.github.io/sqle-docs/
release news https://github.com/actiontech/sqle/releases
Data audit plug-in development documentation https://actiontech.github.io/sqle-docs/docs/dev-manual/plugins/howtouse
Linus took it upon himself to prevent kernel developers from replacing tabs with spaces. His father is one of the few leaders who can write code, his second son is the director of the open source technology department, and his youngest son is an open source core contributor. Robin Li: Natural language will become a new universal programming language. The open source model will fall further and further behind Huawei: It will take 1 year to fully migrate 5,000 commonly used mobile applications to Hongmeng. Java is the language most prone to third-party vulnerabilities. Rich text editor Quill 2.0 has been released with features, reliability and developers. The experience has been greatly improved. Ma Huateng and Zhou Hongyi shook hands to "eliminate grudges." Meta Llama 3 is officially released. Although the open source of Laoxiangji is not the code, the reasons behind it are very heart-warming. Google announced a large-scale restructuring
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/actiontechoss/blog/11053596