博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lower_case_table_names (mysql表名区分大小写)
阅读量:2155 次
发布时间:2019-05-01

本文共 3761 字,大约阅读时间需要 12 分钟。

 

show variables like 'lower_case_table_names';

 

However, this same statement is permitted on Windows. To avoid problems caused by such differences, it is best to adopt a consistent convention, such as always creating and referring to databases and tables using lowercase names. This convention is recommended for maximum portability and ease of use.

How table and database names are stored on disk and used in MySQL is affected by the  system variable, which you can set when starting.  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  is 0. On Windows, the default value is 1. On macOS, the default value is 2.

Value Meaning
0 Table and database names are stored on disk using the lettercase specified in the  or  statement. Name comparisons are case-sensitive. You should not set this variable to 0 if you are running MySQL on a system that has case-insensitive file names (such as Windows or macOS). If you force this variable to 0 with  on a case-insensitive file system and access MyISAM tablenames using different lettercases, index corruption may result.
1 Table names are stored in lowercase on disk and name comparisons are not case-sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.
2 Table and database names are stored on disk using the lettercase specified in the  or  statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case-sensitive. This works only on file systems that are not case-sensitive! InnoDB table names and view names are stored in lowercase, as for lower_case_table_names=1.

If you are using MySQL on only one platform, you do not normally have to change the  variable from its default value. However, you may encounter difficulties if you want to transfer tables between platforms that differ in file system case sensitivity. For example, on Unix, you can have two different tables named my_table and MY_TABLE, but on Windows these two names are considered identical. To avoid data transfer problems arising from lettercase of database or table names, you have two options:

  • Use lower_case_table_names=1 on all systems. The main disadvantage with this is that when you use  or , 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  to 1 on all platforms to force names to be converted to lowercase.

 

变更 操作

If you plan to set the  system variable to 1 on Unix, you must first convert your old database and table names to lowercase before stopping and restarting it with the new variable setting. To do this for an individual table, use :

RENAME TABLE T1 TO t1;

To convert one or more entire databases, dump them before setting , then drop the databases, and reload them after setting:

  1. Use  to dump each database:

    mysqldump --databases db1 > db1.sqlmysqldump --databases db2 > db2.sql...

    Do this for each database that must be recreated.

  2. Use DROP DATABASE to drop each database.

  3. Stop the server, set , and restart the server.

  4. Reload the dump file for each database. Because  is set, each database and table name is converted to lowercase as it is re-created:

    mysql < db1.sqlmysql < db2.sql...

 

 

 

 

 

 

 

 

 

转载地址:http://rkawb.baihongyu.com/

你可能感兴趣的文章
初探Java设计模式5:一文了解Spring涉及到的9种设计模式
查看>>
Java集合详解1:一文读懂ArrayList,Vector与Stack使用方法和实现原理
查看>>
Java集合详解2:一文读懂Queue和LinkedList
查看>>
Java集合详解3:一文读懂Iterator,fail-fast机制与比较器
查看>>
Java集合详解4:一文读懂HashMap和HashTable的区别以及常见面试题
查看>>
Java集合详解5:深入理解LinkedHashMap和LRU缓存
查看>>
Java集合详解6:这次,从头到尾带你解读Java中的红黑树
查看>>
Java集合详解7:一文搞清楚HashSet,TreeSet与LinkedHashSet的异同
查看>>
Java集合详解8:Java集合类细节精讲,细节决定成败
查看>>
Java并发指南1:并发基础与Java多线程
查看>>
Java并发指南2:深入理解Java内存模型JMM
查看>>
Java并发指南3:并发三大问题与volatile关键字,CAS操作
查看>>
Java并发指南4:Java中的锁 Lock和synchronized
查看>>
Java并发指南5:JMM中的final关键字解析
查看>>
Java并发指南6:Java内存模型JMM总结
查看>>
Java并发指南7:JUC的核心类AQS详解
查看>>
Java并发指南8:AQS中的公平锁与非公平锁,Condtion
查看>>
Java网络编程和NIO详解6:Linux epoll实现原理详解
查看>>
Java网络编程和NIO详解7:浅谈 Linux 中NIO Selector 的实现原理
查看>>
Java网络编程与NIO详解8:浅析mmap和Direct Buffer
查看>>