Linux MySQL table name case-sensitive settings and experimental tests

Source: Internet
Author: User

To modify the My.ini file under the MySQL Tutorial Server installation directory, add the following line to the Mysqld section set-variable=lower_case_table_names=0 (0: Case sensitive 1: Case insensitive) finally restart the MySQL service.


1.lower_case_tables_name=0 situation (Linux default)
Start the MySQL tutorial directly and create a new table in the MyTest library mytable and MyTable

mysql> use mytest;
Mysql> CREATE TABLE mytable (ID int not null,name varchar (a), dt date);
Mysql> CREATE TABLE mytable (ID int not null,name varchar (a), dt date);
Mysql> Show tables;
+------------------+
| Tables_in_mytest |
+------------------+
| MyTable |
| MyTable |

+------------------+
By default, you can create mytable and mytable two tables at the same time

2.lower_case_tables_name=1 situation (we need to set it up in this case)
Enter the ETC directory, edit the my.cnf file
[Root@mysqlserver etc]# VI my.cnf
Find [mysqld]
Add a line to the last side of its global variable: lower_case_table_names = 1
Save, exit, and then restart MySQL
[Root@mysqlserver etc]# service mysqld restart;
Access to MySQL
[Root@mysqlserver mysql]# Bin/mysql
mysql> use mytest;
Mysql> select * FROM MyTable;
Mysql> select * FROM MyTable;
Two query results are the same as the query MyTable table, and the MyTable table has not been found (you can see, but not the query)
Let's try to create a mytable table again.
Mysql> CREATE TABLE mytable (ID int not null,name varchar (a), dt date);
Error 1050 (42S01): Table ' mytable ' already exists
Will get a hint that the table already exists

Again, we can try to create a mytest library
mysql> CREATE DATABASE mytest;
Error 1007 (hy000): Can ' t create database ' mytest '; Database exists
You'll also get hints that the library already exists.

In this case, the table and library names are not case-sensitive.

Note: Before Lower_case_tables_name is set to 1 in Unix, you must first convert the old Database tutorial and table names to lowercase before restarting mysqld, otherwise the previous table will not be found

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.