Case sensitivity of table names in MySQL is determined by the host operating system. There are three settings in MySQL that control table name case sensitivity:
- Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement. Name comparisons are case sensitive.
- Table names are stored in lowercase on disk and name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup. This behaviour also applies to database names and table aliases.
- Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive. This works only on file systems that are not case sensitive.
Unix/Linux defaults to 0, Windows to 1, and OS X to 2. Although I primarily use MySQL on Linux, I prefer to set it to 1. Why? Many reasons, but the main one being that I use an Entity Relationship Diagram (ERD) program that exports to MySQL. And in ERDs you write the entity name, which becomes the table name, in uppercase. But when writing queries the convention is to use lowercase. Another reason is for portability. If migrating your database from one operating system to another, setting 1 is compatible with them all.
To change the default you need to edit your my.cnf file:
[mysqld] lower_case_table_names = 1
Note that you need to put this in the [mysqld] section, don't just append it to the end of the file. Don't forget to restart MySQL.
0 comments:
Post a Comment