Linux mysql table name Case sensitivity settings and experimental testing

Source: Internet
Author: User
Tags mysql tutorial

Modify my. ini file. Add the following set-variable = lower_case_table_names = 0 (0: Case Sensitive; 1: Case Insensitive) to the mysqld section and restart the mysql service.


1. lower_case_tables_name = 0 (default in linux)
Start the mysql tutorial directly and create tables mytable and mytable in the mytest database.

Mysql> use mytest;
Mysql> create table mytable (id int not null, name varchar (10), dt date );
Mysql> create table mytable (id int not null, name varchar (10), dt date );
Mysql> show tables;
+ ------------------ +
| Tables_in_mytest |
+ ------------------ +
| Mytable |
| Mytable |

+ ------------------ +
By default, you can create both mytable and mytable tables.

2. lower_case_tables_name = 1 (we need to set this case)
Go to the etc directory and edit the my. cnf file.
[Root @ mysqlserver etc] # vi my. cnf
Find [mysqld]
Add a row at the end of its global variable: lower_case_table_names = 1
Save, exit, and restart mysql
[Root @ mysqlserver etc] # service mysqld restart;
Go to mysql
[Root @ mysqlserver mysql] # bin/mysql
Mysql> use mytest;
Mysql> select * from mytable;
Mysql> select * from mytable;
The results of the two queries are the same. Both queries are mytable tables, but mytable tables cannot be found (as you can see, but cannot be found)
Let's try again to create a mytable table.
Mysql> create table mytable (id int not null, name varchar (10), dt date );
Error 1050 (42s01): table 'mytable' already exists
The table already exists.

Similarly, we can try to create the mytest Library
Mysql> create database mytest;
Error 1007 (hy000): can't create database 'mytest'; database exists
You will also be prompted that the database already exists.

In this case, table names and database names are case insensitive.

Note: Before setting lower_case_tables_name to 1 in unix, you must first convert the tutorial name and Table Name of the old database to lowercase before restarting mysqld. Otherwise, the previous table cannot be found.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.