lower_case_table_names and mutual database migration issues between Linux and windows platform

MySQL on lower_case_table_names document  https://dev.mysql.com/doc/refman/5.7/en/identifier-case-sensitivity.html 

In MySQL, databases correspond to directories within the data directory. Each table within a database corresponds to at least one file within the database directory (and possibly more, depending on the storage engine). Triggers also correspond to files. Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database, table, and trigger names. This means such names are not case-sensitive in Windows, but are case-sensitive in most varieties of Unix. One notable exception is macOS, which is Unix-based but uses a default file system type (HFS+) that is not case-sensitive. However, macOS also supports UFS volumes, which are case-sensitive just as on any Unix. See Section 1.8.1, “MySQL Extensions to Standard SQL”. The lower_case_table_names system variable also affects how the server handles identifier case sensitivity, as described later in this section.

1. The principle components:

 

MySQL database name, table name, trigger name is mapped to a directory and file name. In the following Linux systems, directory and file names are case-sensitive, so the default database name, table name, trigger name is case-sensitive.

However, the following Windows system directory and file names are case-insensitive:

 

 

The figure when we build a a and A in the following folder windows, pop-up prompts; when we build a.txt and A.txt also prompted.

 2. The impact of the default values

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 startingmysqldlower_case_table_names can take the values shown in the following table. This variable does not affect case sensitivity of trigger identifiers. On Unix, the default value of lower_case_table_names is 0. On Windows, the default value is 1. On macOS, the default value is 2.

The following Linux lower_case_table_names default is 0, the default Windows is 1, MacOS default is 2;

They have the following meanings:

lower_case_table_names = 0 watches library name is stored for a given size and is case-sensitive comparison
lower_case_table_names = 1 watches the library name is stored in the disk is lowercase, but when the comparison is not case sensitive
lower_case_table_names = 2 name is stored as a library watches but given the case when comparing lowercase

3. Problems 1:

If you are migrating from Windows platform to Linux platform, the original database and table names are not case-sensitive; for example, a user table, he lowercase storage, but which use sql statement:

select * from user and select * from USER or select * from User are the same as in the look comparisons are not case size;

First to migrate to Linux platform, the library name is lowercase watches store after import, but the library name watches when comparing lookups are case-sensitive, so:

Only select * from user can find the corresponding user table file is stored under Linux, and are unable to find any other form of tables;

Solution : After migration to Linux platform, the value lower_case_table_names changed to 1; that is, to find comparisons are not case sensitive on it;

Risks : for example, that there are Linux platform tuser table and TUSER table, because the original is case-sensitive, they correspond to a different table and store files, and now into not case-sensitive, so the question arises! Table name conflict. However, this is relatively rare. It is still relatively safe.

 

4. Problems 2:

If you are migrating from Linux platform to the Windows platform, the original database and table names are case-sensitive; now migrated to the Windows platform, not case-sensitive,

For example, that there are tuser table and TUSER table, because the original is case-sensitive, they correspond to a different table and store files, and now into not case-sensitive, so the question arises! ! ! Table name conflict! However, this is relatively rare.

Solution : After migrating to the Windows platform, the value lower_case_table_names changed to 0; that is, to find comparisons are case-sensitive on it;

Risks : storage and comparisons are case sensitive a, select, such as original windows platform * from user and select * from USER are legitimate, and now leads select * from USER will not find the name of the table! ! !

So migration from windows to linux platform platform is generally no need to modify the value lower_case_table_names changed to 0, as the case table name conflicts and rare. From case to case insensitive distinguish the following general are compatible.

And then if the windows platform database before the database exists, modify, leading to sql application system can not find the table name, this problem is more serious!

5. Recommendations

  • Use lower_case_table_names=1 on all systems. The main disadvantage with this is that when you use SHOW TABLES or SHOW DATABASES, you do not see the names in their original lettercase.

  • Use lower_case_table_names=0 on Unix and lower_case_table_names=2 on Windows. This preserves the lettercase of database and table names. The disadvantage of this is that you must ensure that your statements always refer to your database and table names with the correct lettercase on Windows. If you transfer your statements to Unix, where lettercase is significant, they do not work if the lettercase is incorrect.

    Exception: If you are using InnoDB tables and you are trying to avoid these data transfer problems, you should set lower_case_table_names to 1 on all platforms to force names to be converted to lowercase.

If there is no different in the case of platform migration, then keep the default values.

If the situation migrating between Linux and Windows platforms exist, then at the beginning of any platform set lower_case_table_names = 1 to avoid problems;

Setting lower_case_table_names = 1 The only problem is, show tables and show databases that you see is not specified when creating a new database tables and uppercase and lowercase letters.

6. Summary

0. In fact, master the principles: MySQL library and table names correspond to file directories and files, and then differentiate Linux directory and file name of the case, but does not distinguish between the Windows platform, other things can be deduced processing;

1. migration between windows and linux platform, we need to modify lower_case_table_names = 1; while Linux migration to the Windows platform, generally do not require modification to change the parameters;

2. At any time beginning on the platform set lower_case_table_names = 1 can solve the platform for migration issues;

Comparative lower_case_table_names controlled not by the name of the trigger 3;

 

Guess you like

Origin www.cnblogs.com/digdeep/p/11441802.html