mac mysql大小写_MacOS上不区分大小写文件系统的MySQL区分大小写表名称

bd96500e110b49cbb3cd949968f18be7.png

I have researched a lot and what I understand to make database tables name sensitive, you have to set the variable lower_case_table_names=0.

Im on osX. I did this change in my.cnf.

After that, if I run

select * from users

I get results. While if I run:

select * from Users

I get error saying table doesn't exist.

However, for a particular database, the case sensitivity doesnt affect. I can use any case I will never receive errors. Why? I could have a look at the big sql-file used to import the database and try to find out if there are specific directives to ignore case sensitivity (?).

Anyway, why you think the case sensitivity applies for all database but not the one Im interested in? One of those that does case sensitivity is InnoDB. While the one that doesnt care about this is MyIsam. Could it be the reason? Any work around in that case?

解决方案

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):

433DT.jpg

Additional References:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL区分大小写体现在以下几个方面[^1]: 1. 数据库名和名:在MySQL中,数据库名和名以小写形式存储在磁盘上,并且在执行SQL语句时会将所有的数据库名、名和别名转换成小写。这意味着无论你在SQL语句中使用大写、小写还是混合大小写的标识符,MySQL都会将其转换为小写进行处理。 2. 文件系统MySQL中的数据库存储在文件系统中的data目录中,每个数据库对应一个子目录,每张对应一个子文件。在Windows系统中,文件系统大小写不敏感的,所以数据库、和底层触发器在Windows系统中不区分大小写。而在大多数Unix系统中,文件系统大小写敏感的,所以数据库、和底层触发器在Unix系统中是区分大小写的。MacOS是一个特例,它的默认文件系统(HFS+)是大小写不敏感的,但也支持大小写敏感的UFS文件系统。 3. 系统变量lower_case_table_names:MySQL服务器的lower_case_table_names系统变量决定了是否区分标识符的大小写。当lower_case_table_names的值为0时,大小写敏感;当值为1时,大小写不敏感;当值为2时,示将标识符转换为小写,并且在比较时也将标识符转换为小写。lower_case_table_names的默认值是0,即大小写敏感。 所以,MySQL区分大小写体现在数据库名、名、文件系统和系统变量lower_case_table_names这几个方面。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值