MySQL case sensitivity table name on MacOS with case insensitive file system

烈酒焚心 提交于 2019-12-01 23:30:14

The case sensitivity of database and table names depends on the underlying OS and file system.

On Windows they are not case sensitive. On Linux they are case sensitive.

OSX is somewhere in the middle; the HFS file system supports both case-sensitive and case-insensitive file names (not on the same time though). It depends on how it was formatted.

Praveen Kumar Purushothaman

Tables and Columns are Case Sensitive in Linux! To make them case insensitive, follow this:

Open terminal and edit /etc/mysql/my.cnf

sudo nano /etc/mysql/my.cnf

Underneath the [mysqld] section, add:

lower_case_table_names = 1

Restart mysql

sudo /etc/init.d/mysql restart

Then check it here:

mysqladmin -u root -p variables

Just altering the lower_case_table_names setting isn't enough. It needs to be done before you import your database(s).

The MySQL 5.7 documentation lists a procedure for moving between Windows and Linux/UNIX. A note about Mac OSX from that reference:

One notable exception is OS X, which is Unix-based but uses a default file system type (HFS+) that is not case sensitive. However, OS X also supports UFS volumes, which are case sensitive just as on any Unix.

Review the manual page to ensure that your desired rules for enforcing case sensitivity are followed. Take a look and verify that you did these steps in the correct order:

To convert one or more entire databases, dump them before setting lower_case_table_names, then drop the databases, and reload them after setting lower_case_table_names:

1 - Use mysqldump to dump each database:

mysqldump --databases db1 > db1.sql

mysqldump --databases db2 > db2.sql

... Do this for each database that must be recreated.

2 - Use DROP DATABASE to drop each database.

3 - Stop the server, set lower_case_table_names in the [mysqld] section of your \etc\mysql\my.cnf file, and restart the server.

4 - Reload the dump file for each database. Because lower_case_table_names is set, each database and table name will be converted to lowercase as it is recreated:

mysql < db1.sql

mysql < db2.sql

Concerning the MySQL System Variable lower_case_table_names Server Variable (or setting):

Additional References:

However, for a particular database, the case sensitivity doesnt affect. I can use any case I will never receive errors. Why?

This is because this database is simply created with option of case-insensitivity (by default). You need first to put case-sensitive option in the top of sql create script before the database creation, so the DBMS takes care.

  1. Locate file at /etc/mysql/my.cnf

  2. Edit the file by adding the following lines:

    [mysqld]

    lower_case_table_names=1

  3. sudo /etc/init.d/mysql restart

You might need to re-create these tables to make it work

mysql manual states:

If you plan to set the lower_case_table_names system variable to 1 on Unix, you must first convert your old database and table names to lowercase before stopping mysqld and restarting it with the new variable setting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!