Can I safely rely on column name case in mysql?

2020-04-10 03:30发布

I want to name my mysql table column names using camel case and create php classes from these mysql tables with the same camel case names. I will be generating these php classes automatically. I'm wondering if I can rely on column name case no matter what platform I run my application on. So for example, if I name one column name "FirstName", will I ever encounter a time where reading the column name from the database will product "firstname" or something like that?

2条回答
别忘想泡老子
2楼-- · 2020-04-10 04:02

Short answer is no.

The long answer is that case-sensitivity for some things in MySQL depend on the underlying operating system. (Unix being the sensitive one)

Here is the reference to the issue in the MySQL documentation.

Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database and table names. This means database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix. One notable exception is Mac OS X, which is Unix-based but uses a default file system type (HFS+) that is not case sensitive.

Also from the documentation on column names specifically:

Column, index, and stored routine names are not case sensitive on any platform, nor are column aliases. Trigger names are case sensitive, which differs from standard SQL.

查看更多
Evening l夕情丶
3楼-- · 2020-04-10 04:21

MySQL is case sensitive in table and column names, and case in-sensitive in keywords.

But note that Windows is only case preserving, and file names are table names. (If you work on table "SalesAccounts" when you meant "Salesaccounts" then it will read OK on Windows and fail on Linux.

You should be OK with what you want to do, but 1) Test on Linux, 2) Test the tools you are using.

查看更多
登录 后发表回答