mysql中已經存在某個庫中有大小寫的表,將lower_case_table_names由0改為1對已經存在的表是否有影響?


需求描述:

  今天遇到了修改lower_case_table_names參數的問題,想了下,如果原來里面有表,表名有大小寫的,

  如果將lower_case_table_names從默認的0改為1之后,那么對於原來的表有沒有影響.做個實驗,在此

  記錄下.

操作過程:

1.原來未修改之前,庫中創建大小寫區分的表

mysql> drop database test05;
Query OK, 2 rows affected (0.05 sec)

mysql> create database test05;
Query OK, 1 row affected (0.00 sec)

mysql> use test05;
Database changed
mysql> create table tab01(id int); #創建小寫的表名
Query OK, 0 rows affected (0.05 sec)

mysql> create table Tab01(id int); #創建大寫的表名
Query OK, 0 rows affected (0.04 sec)

mysql> insert into tab01 select 1; #分別向兩個表中插入數據
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into tab01 select 2;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into tab01 select 3;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into tab01 select 4;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into Tab01 select 4;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into Tab01 select 5;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into Tab01 select 6;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from tab01; #小寫表名中的數據
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
+------+
4 rows in set (0.00 sec)

mysql> select * from Tab01; #大寫表名中的數據
+------+
| id   |
+------+
|    4 |
|    5 |
|    6 |
+------+
3 rows in set (0.00 sec)

2.將lower_case_table_name參數修改為1,重啟實例

mysql> select * from Tab01; #查詢大寫表名,發現是小寫表的數據
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    2
Current database: test05

+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
+------+
4 rows in set (0.01 sec)

mysql> select * from tab01; #查詢小寫表名,還是小寫表的數據
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
+------+
4 rows in set (0.00 sec)

mysql> system ls -l /mysql/data/test05  #操作系統上大小寫文件都是存在的.
total 220
-rw-r----- 1 mysql mysql    61 Jun  5 17:03 db.opt
-rw-r----- 1 mysql mysql  8556 Jun  5 17:03 tab01.frm
-rw-r----- 1 mysql mysql  8556 Jun  5 17:04 Tab01.frm
-rw-r----- 1 mysql mysql 98304 Jun  5 17:04 tab01.ibd
-rw-r----- 1 mysql mysql 98304 Jun  5 17:05 Tab01.ibd
mysql> insert into Tab01 select * from tab01;  #繼續向大寫表名中插數據.
Query OK, 4 rows affected (0.05 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> system ls -l /mysql/data/test05
total 220
-rw-r----- 1 mysql mysql    61 Jun  5 17:03 db.opt
-rw-r----- 1 mysql mysql  8556 Jun  5 17:03 tab01.frm
-rw-r----- 1 mysql mysql  8556 Jun  5 17:04 Tab01.frm
-rw-r----- 1 mysql mysql 98304 Jun  5 17:07 tab01.ibd
-rw-r----- 1 mysql mysql 98304 Jun  5 17:05 Tab01.ibd
mysql> insert into Tab01 select * from tab01;
Query OK, 8 rows affected (0.01 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> system ls -l /mysql/data/test05
total 220
-rw-r----- 1 mysql mysql    61 Jun  5 17:03 db.opt
-rw-r----- 1 mysql mysql  8556 Jun  5 17:03 tab01.frm
-rw-r----- 1 mysql mysql  8556 Jun  5 17:04 Tab01.frm
-rw-r----- 1 mysql mysql 98304 Jun  5 17:07 tab01.ibd  
-rw-r----- 1 mysql mysql 98304 Jun  5 17:05 Tab01.ibd
mysql> insert into Tab01 select * from tab01;
Query OK, 16 rows affected (0.00 sec)
Records: 16  Duplicates: 0  Warnings: 0

mysql> system ls -l /mysql/data/test05
total 220
-rw-r----- 1 mysql mysql    61 Jun  5 17:03 db.opt
-rw-r----- 1 mysql mysql  8556 Jun  5 17:03 tab01.frm
-rw-r----- 1 mysql mysql  8556 Jun  5 17:04 Tab01.frm
-rw-r----- 1 mysql mysql 98304 Jun  5 17:07 tab01.ibd
-rw-r----- 1 mysql mysql 98304 Jun  5 17:05 Tab01.ibd
mysql> insert into Tab01 select * from tab01;
Query OK, 32 rows affected (0.01 sec)
Records: 32  Duplicates: 0  Warnings: 0

mysql> insert into Tab01 select * from tab01;
Query OK, 64 rows affected (0.01 sec)
Records: 64  Duplicates: 0  Warnings: 0

mysql> insert into Tab01 select * from tab01;
Query OK, 128 rows affected (0.02 sec)
Records: 128  Duplicates: 0  Warnings: 0

mysql> insert into Tab01 select * from tab01;
Query OK, 256 rows affected (0.00 sec)
Records: 256  Duplicates: 0  Warnings: 0

mysql> insert into Tab01 select * from tab01;
Query OK, 512 rows affected (0.02 sec)
Records: 512  Duplicates: 0  Warnings: 0

mysql> insert into Tab01 select * from tab01;
Query OK, 1024 rows affected (0.03 sec)
Records: 1024  Duplicates: 0  Warnings: 0

mysql> system ls -l /mysql/data/test05
total 288
-rw-r----- 1 mysql mysql     61 Jun  5 17:03 db.opt
-rw-r----- 1 mysql mysql   8556 Jun  5 17:03 tab01.frm
-rw-r----- 1 mysql mysql   8556 Jun  5 17:04 Tab01.frm
-rw-r----- 1 mysql mysql 163840 Jun  5 17:08 tab01.ibd  #插入多次發現,只有小寫表名的文件大小在變化.
-rw-r----- 1 mysql mysql  98304 Jun  5 17:05 Tab01.ibd
mysql> system ls -l /mysql/data/test05
total 288
-rw-r----- 1 mysql mysql     61 Jun  5 17:03 db.opt
-rw-r----- 1 mysql mysql   8556 Jun  5 17:03 tab01.frm
-rw-r----- 1 mysql mysql   8556 Jun  5 17:04 Tab01.frm
-rw-r----- 1 mysql mysql 163840 Jun  5 17:08 tab01.ibd
-rw-r----- 1 mysql mysql  98304 Jun  5 17:05 Tab01.ibd

 

備注:發現將lower_case_table_names參數從默認的0改為1之后,對於原來表的使用是有影響的,查詢的也只是查詢小寫的表,插入也只是插入到小寫的表中,雖然通過show tables能夠看到大小寫的表同時存在.

 

文檔創建時間:2018年6月5日17:20:23


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM