您的位置:首页 > 数据库 > MySQL

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

2014-10-16 10:28 274 查看
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 the
lower_case_table_names
system
variable, which you can set when starting mysqld.
lower_case_table_names
can
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.

ValueMeaning
0
Table and database names are stored on disk using the lettercase specified in the
CREATE
TABLE
or
CREATE
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
or
CREATE
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: