天天看點

修改lower_case_table_names産生的問題

1、參數含義:

lower_case_table_names: 此參數不可以動态修改,必須重新開機資料庫

lower_case_table_names = 1  表名存儲在磁盤是小寫的,但是比較的時候是不區分大小寫

lower_case_table_names=0  表名存儲為給定的大小和比較是區分大小寫的 

lower_case_table_names=2, 表名存儲為給定的大小寫但是比較的時候是小寫的

2、修改  參數lower_case_table_names 産生的問題

mysql> show variables like 'lower_case_table_names';

+------------------------+-------+

| Variable_name          | Value |

+------------------------+-------+

| lower_case_table_names | 0     |

+------------------------+-------+

1 row in set (0.00 sec)

在mysql系統中原來的參數是lower_case_table_names=0 ,就是存儲的時候區分大小寫,建立了表Tt  tT 

mysql>  create table Tt(id int);

Query OK, 0 rows affected (0.10 sec)

mysql>  create table tT(id int);

Query OK, 0 rows affected (0.03 sec)

mysql> show tables;

+----------------+

| Tables_in_test |

+----------------+

| Tt             |

| tT             |

+----------------+

2 rows in set (0.00 sec)

修改參數 /etc/my.cnf 中設定 lower_case_table_names = 1

mysql> show  variables like 'lower_case_table_names';

+------------------------+-------+

| Variable_name          | Value |

+------------------------+-------+

| lower_case_table_names | 1     |

+------------------------+-------+

1 row in set (0.00 sec)

重新開機資料庫

然後檢視資料庫

mysql> select * From tT;

ERROR 1146 (42S02): Table 'test.tt' doesn't exist

mysql> select * From tT;

ERROR 1146 (42S02): Table 'test.tt' doesn't exist

你可以發現當修改lower_case_table_names = 1後,之前建立的表名都不識别了

---建立表後,你可以發現表名不區分大小寫

mysql> create table Tt(id int);

Query OK, 0 rows affected (0.23 sec)

mysql> show tables;

+-------------+

| Tables_in_t |

+-------------+

| tt          |

+-------------+

1 row in set (0.00 sec)

從此可以看出lower_case_table_names = 1,建立表名,不區分大小寫

結論:不能随意修改資料庫的大小寫,否則表名會認不出來

lower_case_table_names 參數的修改是非動态的,必須重新開機資料庫

3、如何修改大小寫格式

如果原來所建立庫及表都是對大小寫敏感的,想要轉換為對大小寫不敏感,主要需要進行如下3步:

    1.将資料庫資料通過mysqldump導出;

    2.在my.cnf中更改lower_case_tables_name = 1,并重新開機mysql資料庫。

    3.将導出的資料導入mysql資料庫中。

On Windows the default value is 1. On OS X, the default value is 2.

If you are using InnoDB tables, you should set this variable to 1 on all platforms to force names to be converted to lowercase.

In previous versions of MySQL, using different settings for lower_case_table_names on replication masters and slaves could cause replication to fail when the slave used a case-sensitive file system. This issue is resolved in MySQL 5.6.1.

You should not set lower_case_table_names to 0 if you are running MySQL on a system where the data directory resides on a case-insensitive file system (such as on Windows or OS X). It is an unsupported combination that could result in a hang condition when running an INSERT INTO ... SELECT ... FROM tbl_name operation with the wrong tbl_name letter case. WithMyISAM, accessing table names using different letter cases could cause index corruption.

---------------------