jpa在mysql中自动创建重复表,只是大小写不同

jpa在mysql中自动创建重复表,只是大小写不同


可通过加入环境变量解决 lower_case_table_names 


参考资料:

http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html

http://www.alberton.info/dbms_identifiers_and_case_sensitivity.html


However, this same statement is permitted on Windows. To avoid problems caused by such differences, it is best to adopt a consistent convention, such as always creating and referring to databases and tables using lowercase names. This convention is recommended for maximum portability and ease of use.

How table and database names are stored on disk and used in MySQL is affected by thelower_case_table_names system variable, which you can set when starting mysqldlower_case_table_namescan take the values shown in the following table. On Unix, the default value of lower_case_table_names is 0. On Windows the default value is 1. On Mac OS X, the default value is 2.

Value Meaning
0 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE orCREATE DATABASE statement. Name comparisons are case sensitive. You should not set this variable to 0 if you are running MySQL on a system that has case-insensitive file names (such as Windows or Mac OS X). If you force this variable to 0 with --lower-case-table-names=0 on a case-insensitive file system and access MyISAM tablenames using different lettercases, index corruption may result.
1 Table names are stored in lowercase on disk and name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.
2 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE orCREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive. This works only on file systems that are not case sensitive! InnoDB table names are stored in lowercase, as for lower_case_table_names=1.

MySQL

Since MySQL stores each table into a file with the same name in the file system, we can expect it to behave differently depending on the OS where it's installed.


On Windows:

-- test table names and case sensitivity
CREATE TABLE TEST_CASE (id INTEGER);   --ok, test_case table created
CREATE TABLE `Test_Case` (id INTEGER); --fails: already exists
CREATE TABLE `test_case` (id INTEGER); --fails: already exists
CREATE TABLE `TEST_CASE` (id INTEGER); --fails: already exists
 
ALTER TABLE TEST_CASE ADD TeSt INTEGER;   --ok, TeSt field created
ALTER TABLE TEST_CASE ADD `TeSt` INTEGER; --fails: already exists
ALTER TABLE TEST_CASE ADD `test` INTEGER; --fails: already exists
ALTER TABLE TEST_CASE ADD `TEST` INTEGER; --fails: already exists
 
INSERT INTO test_case (id) VALUES (1);   --record inserted into test_case table
INSERT INTO `test_case` (id) VALUES (1); --record inserted into test_case table
INSERT INTO `Test_Case` (id) VALUES (1); --record inserted into test_case table
INSERT INTO `TEST_CASE` (id) VALUES (1); --record inserted into test_case table
INSERT INTO `TEST_case` (id) VALUES (1); --record inserted into test_case table

On Unix/Linux:

-- test table names and case sensitivity
CREATE TABLE Test_Case (id INTEGER);   --ok, Test_Case created
CREATE TABLE `Test_Case` (id INTEGER); --fails: already exists
CREATE TABLE `test_case` (id INTEGER); --ok, test_case created
CREATE TABLE `TEST_CASE` (id INTEGER); --ok, TEST_CASE created
 
ALTER TABLE TEST_CASE ADD TeSt INTEGER;   --ok, TeSt field created
ALTER TABLE TEST_CASE ADD `TeSt` INTEGER; --fails: already exists
ALTER TABLE TEST_CASE ADD `test` INTEGER; --fails: already exists
ALTER TABLE TEST_CASE ADD `TEST` INTEGER; --fails: already exists
 
INSERT INTO Test_Case (id) VALUES (1);   --record inserted into Test_Case table
INSERT INTO `test_case` (id) VALUES (1); --record inserted into test_case table
INSERT INTO `Test_Case` (id) VALUES (1); --record inserted into Test_Case table
INSERT INTO `TEST_CASE` (id) VALUES (1); --record inserted into TEST_CASE table
INSERT INTO `TEST_case` (id) VALUES (1); --fails: TEST_case table doesn't exists

Some interesting observations: on Windows, the table name is lowercased if unquoted, while on *nix the case is preserved. That's because of the default value of thelower_case_table_names system variable, which is different on the two systems.
In all the platforms, the case in the field names is preserved, but no two column


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值