库名表名大小写问题与SQLServer兼容的启动配置方法

很文博客hinven.com 数据库评论411字数 1192阅读模式
广告也精彩

库名表名大小写问题与sqlserver兼容的启动配置方法,需要的朋友可以参考下。
将全局变量 lower_case_table_names 设置为1

实验:
1.lower_case_tables_name=0的情况(Linux默认)
直接启动mysql,在mytest库中新建表MyTable和mytable
mysql> use mytest;
mysql> create table MyTable(id int not null,name varchar(10),dt date);
mysql> create table mytable(id int not null,name varchar(10),dt date);
mysql> show tables;
+------------------+
| Tables_in_mytest |
+------------------+
| MyTable |
| mytable |
+------------------+
默认情况下,可以同时创建mytable和MyTable两个表文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/29487.html

2.lower_case_tables_name=1的情况(我们需要设置成这种情况)
进入到etc目录,编辑my.cnf文件
[root@MYSQLServer etc]# vi my.cnf
找到 [mysqld]
在它的全局变量的最后面加入一行:lower_case_table_names = 1
保存,退出,然后重新启动mysql
[root@MYSQLServer etc]# service mysqld restart;
进入到mysql
[root@MYSQLServer mysql]# bin/mysql
mysql> use mytest;
mysql> select * from MyTable;
mysql> select * from mytable;
两个查询的结果一样,都是查询mytable表,而MyTable表已经找不到了(可以看到,但查询不到)
我们再试着创建MyTable表
mysql> create table MyTable(id int not null,name varchar(10),dt date);
ERROR 1050 (42S01): Table 'mytable' already exists
将得到表已经存在的提示文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/29487.html

同样,我们可以试着创建MyTest库
mysql> create database MyTest;
ERROR 1007 (HY000): Can't create database 'mytest'; database exists
也会得到库已经存在的提示文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/29487.html

在这种情况下,表名和库名都不区分大小写了。文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/29487.html

注意:在Unix中将lower_case_tables_name设置为1之前,重启mysqld之前, 必须先将旧的数据库名和表名转换为小写,否则设置后,将找不到以前的表。
(上面的实验中,MyTable表在lower_case_tables_name=1时已经找不到了)文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/29487.html 文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/29487.html

工具:作品在线观看

女优:最新作品观看

中文:国语在线观看

weinxin
我的微信
扫一扫更精彩
大家的支持是我更新的动力!!!
 
  • 配置方法
  • 库名表名
  • SQLServer
广告也精彩
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证