The upper, lower, or camel-casing of MySQL table names is rarely something developers consider. Unfortunately, it can cause major headaches if you are intending to port your application from a Windows or Mac development environment to a Linux or Unix-based host.
Table Name Case Sensitivity
Each table in a MySQL database corresponds to a physical .frm file within the database folder. Therefore, the case sensitivity of your tables relies on the underlying Operating System. For example, assume we have created the following table and filled it with data:
CREATE MyTable (
id SMALLINT unsigned NOT NULL,
name VARCHAR(50)
)
We then run the following query in our code:
SELECT id, name FROM mytable WHERE id = 1;
This query will work correctly on a Windows or Mac host. Unfortunately, it will fail once your application is copied to Linux or Unix.
Note that database, table, and trigger names are affected by case sensitivity. Columns, indexes, stored procedures, event names and aliases are not case-sensitive.
lower_case_table_names
lower_case_table_names is a MySQL system variable which controls how the database resolves table name casing. It can be passed as a start-up parameter for mysqld or within my.ini (although this is known to cause earlier versions of MySQL to fail). The value can be set to:
0 (Linux/Unix default)
Table name comparisons are case sensitive. Tables are stored on disk using the letter case specified.
1 (Windows default)
Table name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup.
2 (Mac default)
Table name comparisons are not case sensitive. MyISAM tables are stored on disk using the letter case specified, but MySQL converts them to lowercase on lookup. InnoDB tables are stored in lowercase.
It is therefore tempting to set lower_case_table_names to zero on your system. However, Windows users should not do that. The manual warns that if you set lower-case-table-names=0 on a case-insensitive file system and access MyISAM table names using different letter cases, index corruption may result. Nasty.
Recommendations
Personally, I prefer to use lowercase naming conventions for all databases, tables, indexes, keys and other MySQL names. That appears to be the easiest solution.
See also:
- MySQL manual: Identifier Case Sensitivity
- MySQL: the Pros and Cons of MyISAM Tables
- MySQL: the Pros and Cons of InnoDB Tables
- How to Use MySQL Foreign Keys for Quicker Database Development
Has MySQL table casing ever caught you out?
Related posts:
- Free Performance with MySQL Table Types Last week, SitePoint launched its second Twitaway, giving away a...
- MySQL: the Pros and Cons of MyISAM Tables MySQL offers several database table types, but which is suitable...
- MySQL: the Pros and Cons of InnoDB Tables Craig discusses why the lesser-used MySQL InnoDB table engine might...
- How to Install MySQL Installing MySQL is easier than you think. Craig provides a...
- 11 Virtual Machine Solutions To Ease Your Cross-Platform Checks Who needs two computers when you have virtual machines? Sean...







We got caught out once, way back, exactly as you describe. We had developed and tested the application on Windows, then scratched our heads for half an hour when we deployed to the production Linux servers and the logs filled with “table not found” errors.
Now, I always use all lower case for everything!
May 15th, 2009 at 7:07 pm
I’ve been caught out by other people’s code. TheY weRe coding in the SPirit of vaRIetY being the spIcE of Life :)
May 15th, 2009 at 8:16 pm
You need to be careful with the CapitalCasedAccessPorts as well.
May 15th, 2009 at 8:20 pm
I just make sure I get the correct case… but I rarely (if at all) use uppercase characters in table names, or column names.
May 15th, 2009 at 9:14 pm
AS/400 DB2 always returns both table and ‘column’ names in uppercase. I always use uppercase.
May 16th, 2009 at 8:11 pm