今天就跟大家聊聊有关如何理解MySQL关于表名大小写的参数,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
查看现有的大小写参数
[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
看完上述内容,你们对如何理解MySQL关于表名大小写的参数有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。