MySQL is a SELECT statement case sensitive?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
MySQL is an open-source relational database management system (RDBMS) that provides users the ability to manage databases and perform various operations on the data stored within them. One of the core functionalities of MySQL is the execution of SQL queries, with the SELECT statement being the most frequently used to retrieve data. A common question among developers and database administrators is whether the SELECT statement and its components are case-sensitive.
Case Sensitivity in MySQL
In MySQL, the case sensitivity of SQL queries and their components is dependent on several factors, including the operating system, the server settings, and the context within which data is being accessed.
SQL Keywords and Commands
MySQL treats SQL keywords and commands as case-insensitive. This means that SELECT, select, Select, and any other variation, are interpreted the same way. Therefore, a SELECT statement can be written in any case without impacting its functionality or results.
Each of the above commands will be treated equally by MySQL.
Case Sensitivity of Identifiers
Identifiers refer to names of databases, tables, columns, indexes, and aliases. The case sensitivity of identifiers in MySQL is a bit more nuanced and can depend on several factors.
Database and Table Names
The case sensitivity of database and table names is controlled by the lower_case_table_names system variable, which behaves differently based on the operating system.
- Unix-based Systems: By default, database and table names are case-sensitive because Unix and Linux file systems are case-sensitive.
- Windows Systems: By default, database and table names are not case-sensitive. This is because Windows file systems are not case-sensitive.
- macOS Systems: Like Windows, macOS is not case-sensitive by default, although it can be configured differently.
For cross-platform compatibility, it is recommended to use lowercase names for database objects.
Column and Alias Names
In MySQL, column names are case-insensitive by default. This is consistent across different operating systems. Similarly, alias names used in queries are also case-insensitive.
Case Sensitivity in String Comparison
String comparisons in MySQL can be case-sensitive or case-insensitive, depending on the collation used by the database. Each character set can have several collations, including those that are case-sensitive (e.g., utf8_bin) or case-insensitive (e.g., utf8_general_ci).
To enforce case sensitivity during string comparison, the binary keyword or a case-sensitive collation must be used:
Summary Table
The following table provides a quick summary of case sensitivity in different aspects of the MySQL SELECT statement:
| Category | Default Case Sensitivity | Factors Affecting Sensitivity |
| SQL Keywords/Commands | Case-insensitive | None |
| Database/Table Names | Varies with OS | OS type, lower_case_table_names setting |
| Column/Field Names | Case-insensitive | None |
| Alias Names | Case-insensitive | None |
| String Comparisons | Depends on collation | Character set and collation settings |
Conclusion
Understanding the case sensitivity behavior of the MySQL SELECT statement and its components is crucial for writing efficient and portable SQL code. While MySQL provides default behaviors, they can be influenced by specific server settings, operating system characteristics, and the chosen collation. To achieve consistent behavior across different platforms, developers are encouraged to adhere to conventions such as using lowercase names for database objects and being mindful of collation settings for string comparisons.
Related reading
- MySql is it possible to 'SUM IF' or to 'COUNT IF'?
- mysql is not recognised as an internal or external command,operable program or batch
- MySQL JDBC Driver 5.1.33 - Time Zone Issue
- MySQL JDBC Driver 5.1.33 - Time Zone Issue
- MySQL JOIN ON vs USING?
- MySQL JOIN the most recent row only?
- MySQL join with where clause
- MySQL Large VARCHAR vs. TEXT?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.