我可以在不区分大小写的文件系统上强制 MySql 表名区分大小写吗
所以我们的目标环境是linux,让mysql默认区分大小写。我知道我们可以使用 lower_case_table_names 变量使我们的 Linux 环境不区分大小写,但我们宁愿不这样做。我们有几次遇到大小写不匹配的问题,因为我们的开发设备是 OSX,而 mysql 在那里不区分大小写。
有没有一种方法可以强制表名在我的 OSX 安装的 MySql(5.0.83,如果重要的话)上区分大小写,以便我们在部署到在 Linux 上运行的集成服务器之前捕获表名大小写不匹配的情况?
So our target environment is linux, making mysql case-sensitive by default. I am aware that we can make our linux environment not case sensitive with the lower_case_table_names variable, but we would rather not. We have a few times been bitten with a case mismatch because our dev rigs are OSX, and mysql is not case sensitive there.
Is there a way we can force table names to be case sensitive on my OSX install of MySql (5.0.83 if that matters) so that we catch a table name case mismatch prior to deploying to the integration servers running on linux?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
my.cnf
中设置lower_case_table_names=0
。如果您通过自制程序安装,则该文件位于此处:
/usr/local/Cellar/mysql//my.cnf
表查询现在应区分大小写:
<代码>
mysql>从用户中选择计数(*);
错误 1146 (42S02):表“xxx.user”不存在
mysql>从用户中选择计数(*);
+----------+
|计数(*)|
+----------+
| 1 |
+----------+
1 行一组(0.00 秒)
Set
lower_case_table_names=0
inmy.cnf
.If you installed via homebrew, the file is here:
/usr/local/Cellar/mysql/<version>/my.cnf
Queries with tables should now be case sensitive:
mysql> select count(*) from user;
ERROR 1146 (42S02): Table 'xxx.user' doesn't exist
mysql> select count(*) from User;
+----------+
| count(*) |
+----------+
| 1 |
+----------+
1 row in set (0.00 sec)
此处最好的做法是修复表名称,以免出现任何冲突。仅根据大小写进行区分是一个坏主意,并且会导致混乱(正如您可能知道的那样)。
但请尝试在创建过程中在表名称周围使用单引号。这适用于 SUSE/Linux/MySQL 5.0,查询浏览器在 Windows 上运行。
如果不区分大小写的客户端请求使用错误大小写的表,您是否希望它失败?我相信如果 MySQL 数据库在 Linux 上运行,它应该会失败。
查看此链接
“一个值得注意的例外是 Mac OS X,它基于 Unix,但使用不区分大小写的默认文件系统类型 (HFS+)。但是,Mac OS X 还支持 UFS 卷,与任何 Unix 上一样区分大小写。 ”
The best thing to do here is fix your table names so that there aren't any conflicts. Differentiating solely by case is a bad idea, and leads to confusion (as you probably know).
But try using single quote marks around the table names during creation. This works on SUSE/Linux/MySQL 5.0 with the query browser running on windows.
Do you want it to fail if a non-case sensitive client requests a table using the wrong case? I believe it should fail if the MySQL database is running on Linux.
Check out this link
"One notable exception is Mac OS X, which is Unix-based but uses a default file system type (HFS+) that is not case sensitive. However, Mac OS X also supports UFS volumes, which are case sensitive just as on any Unix."