MySQL database case sensitivity issue

MySQL database case sensitivity issue

In MySQL, databases correspond to directories within the data directory. Each table in the database corresponds to at least one file in the database directory (or multiple files, depending on the storage engine). Therefore, the case sensitivity of the operating system you are using determines the case sensitivity of database and table names. This means that database and table names are case-sensitive in most Unix systems, but not in Windows. A notable exception is Mac OS X, which is based on Unix but uses a default file system type (HFS+) that is case-insensitive.

Table names are not case-sensitive in Windows, so after importing data, it is possible that all table names are lowercase. After importing from Windows to Linux, case issues are likely to occur when calling. For example:

First point: The program call table name is: codetc_Web;

Second point: After importing win, it becomes codetc_web;

The third point: After importing into Linux, it is still codetc_web. At this time, Linux will distinguish between uppercase and lowercase letters of the table name, which will cause the table to be unreadable.

Solution to the case problem of MySQL table names under Linux:

Modify my.cnf, which is usually located at: /etc/my.cnf, find the [mysqld] section in the file and add the following statement (note that if the statement already exists, change the value to 1):

lower_case_table_names=1

1. After installing MySQL in Linux, the default is: table names are case-sensitive, but column names are not case-sensitive;

2. After logging in with the root account, add lower_case_table_names=1 after [mysqld] in /etc/my.cnf and restart the MYSQL service. The setting is now successful: table names are not case sensitive;

Detailed explanation of the lower_case_table_names parameter:

lower_case_table_names = 0或1

0: case sensitive, 1: case insensitive

The case rules for MySQL database names, table names, column names, and aliases under Linux are as follows:

1. Database names and table names are strictly case-sensitive;

2. The table alias is strictly case-sensitive;

3. Column names and column aliases are case-insensitive in all cases;

4. Variable names are also strictly case-sensitive;

MySQL is not case-sensitive under Windows. If you need to distinguish the case of field values ​​when querying, you need to set the BINARY attribute for the query field value. There are several ways to set it:

(1) Setting at creation time:

CREATE TABLE T(A VARCHAR(10) BINARY);

(2) Use alter to modify:

ALTER TABLE `tablename` MODIFY COLUMN `cloname` VARCHAR(45) BINARY;

(3) Directly check the BINARY item in the MySQL table editor.

To make MySQL query case sensitive, you can:

select * from table_name where binary a like 'a%'  
select * from table_name where binary a like 'A%'

You can also mark it when creating a table

create table table_name( 
   a varchar (20) binary
)

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Notes on MySQL case sensitivity
  • MySQL character types are case sensitive
  • How to set mysql to case insensitive
  • Analysis of problems caused by MySQL case sensitivity
  • How to solve the problem of case insensitivity in MySQL queries
  • Detailed explanation of MySQL table name case-insensitive configuration method
  • Linux system MySQL forgotten password, reset password, ignore the case of table and column names
  • How to distinguish uppercase and lowercase letters in strings when querying MySQL
  • MySql query case insensitive solution (two)
  • MySQL table name case selection

<<:  Tutorial diagram of installing TomCat in Windows 10

>>:  Detailed tutorial on Tomcat installation and deployment in Windows 10

Recommend

Echarts Bar horizontal bar chart example code

Table of contents Horizontal bar chart Dynamicall...

React event mechanism source code analysis

Table of contents Principle Source code analysis ...

Vue opens a new window and implements a graphic example of parameter transfer

The function I want to achieve is to open a new w...

How to install Oracle on Windows Server 2016

1. Install Oracle There are too many Oracle insta...

The latest graphic tutorial of mysql 8.0.16 winx64 installation under win10

In order to download this database, it takes a lo...

JavaScript to implement random roll call web page

JavaScript writes a random roll call webpage for ...

How to disable foreign key constraint checking in MySQL child tables

Prepare: Define a teacher table and a student tab...

What is html file? How to open html file

HTML stands for Hypertext Markup Language. Nowada...

Attributes in vue v-for loop object

Table of contents 1. Values ​​within loop objects...

Compatibility with the inline-block property

<br />A year ago, there were no articles abo...

The DOCTYPE mode selection mechanism of well-known browsers

Document Scope This article covers mode switching...

Python 3.7 installation tutorial for MacBook

The detailed process of installing python3.7.0 on...