MySQL 關於表名大小寫的引數

feelpurple發表於2017-03-21
檢視現有的大小寫引數
[mysql@localhost percona]$ bin/mysql --defaults-file=/u01/mysql_data/my.cnf -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.17-11-log Percona Server (GPL), Release 11, Revision f60191c

mysql> show variables like '%lower%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_file_system | OFF   |
| lower_case_table_names | 1     |
+------------------------+-------+
2 rows in set (0.00 sec)

lower_case_table_names的值為1,代表資料庫的表名不區分大小寫

mysql> use test
Database changed

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| b              |
| c              |
| cpu_stat       |
| p              |
| support_his    |
| t              |
| v_t            |
| z              |
+----------------+
8 rows in set (0.00 sec)

mysql> select * from t;
+---+
| a |
+---+
| 1 |
| 2 |
| 3 |
+---+
3 rows in set (0.04 sec)

mysql> select * from T;
+---+
| a |
+---+
| 1 |
| 2 |
| 3 |
+---+
3 rows in set (0.00 sec)

這個引數是靜態引數,不能線上修改,需要修改配置檔案
mysql> set global lower_case_table_names=0;
ERROR 1238 (HY000): Variable 'lower_case_table_names' is a read only variable

關閉資料庫
[mysql@localhost percona]$ bin/mysqladmin -uroot -S /u01/mysql_data/mysql.sock shutdown -p

修改引數
[mysql@localhost percona]$ vim /u01/mysql_data/my.cnf
[mysqld]
lower_case_table_names                          = 0

重啟資料庫
[mysql@localhost percona]$ bin/mysqld_safe --defaults-file=/u01/mysql_data/my.cnf &

[mysql@localhost percona]$ bin/mysql --defaults-file=/u01/mysql_data/my.cnf -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17-11-log Percona Server (GPL), Release 11, Revision f60191c

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test
Database changed
mysql> show variables like '%lower%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_file_system | OFF   |
| lower_case_table_names | 0     |
+------------------------+-------+
2 rows in set (0.01 sec)

mysql> select * from T;
ERROR 1146 (42S02): Table 'test.T' doesn't exist
mysql> select * from t;
+---+
| a |
+---+
| 1 |
| 2 |
| 3 |
+---+
3 rows in set (0.02 sec)

注意:不建議在生產庫上面修改這個引數,可能導致現有的庫不能使用


引數lower_case_file_system決定作業系統中檔名的大小寫,是隻讀的,不能修改


[mysql@localhost percona]$ cd /u01/mysql_data/test/
[mysql@localhost test]$ ls
b.frm  b.ibd  c.frm  c.ibd  cpu_stat.frm  cpu_stat.ibd  db.opt  p.frm  p.ibd  support_his.frm  support_his.ibd  t.frm  t.ibd  v_t.frm  z.frm  z.ibd

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2135770/,如需轉載,請註明出處,否則將追究法律責任。

相關文章