---
title: "mysql数据库迁移到新的实例可能遇到的坑-mysql5.7"
author: "dbp_cn"
date: "2018-06-04T15:10:32Z"
tags: []
categories: ["数据库"]
slug: "mysql-mysql5-7"
draft: false
lastmod: "2018-06-04T16:44:36Z"
id: 2424237
url: "https://dbp5588.iteye.com/blog/2424237"
---

一、 mysql数据库导入sql文件时提示“Error Code: 1153 - Got a packet bigger than 'max\_allowed\_packet' bytes”

1.查看目前数据库配置

show VARIABLES like '%max\_allowed\_packet%';

显示如下结果

+--------------------+---------+

| Variable\_name      | Value   |

+--------------------+---------+

| max\_allowed\_packet | 1048576 |

+--------------------+---------+

说明目前的配置是：1048576/1024/1024 = 1M

 

二、mysql 忽略表名大小写

**因为linux下mysql默认是要区分表名大小写的**。mysql是否区分大小写设置是由参数lower\_case\_table\_names决定的

lower\_case\_table\_names = 1   
不区分大小写（即对表名大小写不敏感）。这样设置后，表名在硬盘上以小写保存，MySQL将所有表名转换为小写存储和查找表上。**该行为也适合数据库名和表的别名**。  
也就是说，mysql设置为不分区大小写后，创建库或表时，不管创建时使用大写字母，创建成功后，都是强制以小写保存！

修改配置文件：

\[root@test-huanqiu ~]# cat /etc/my.cnf                                          //添加下面一行设置  
.....  
\[mysqld]  
lower\_case\_table\_names=1

 

三、mysql5.7.x:this is incompatible with DISTINCT

DISTINCT关键字经常在MySQL中使用，在mysql5.7以前的版本中一般没有什么问题，但是在5.7以后的版本中会遇到这样的错误

Caused by: java.sql.SQLException: Expression #1 of ORDER BY clause is not in SELECT list, references column ‘game.giftbag0\_.create\_date’ which is not in SELECT list; this is incompatible with DISTINCT

 

错误提示DISTINCT不兼容，要么更改SQL，但是对于开发者来讲，sql运行一直都是正常的，可能是mysql 版本升级导致的安全问题，5.7.x安全性提升了很多，解决办法可以考虑修改MySQL配置文件,找到对应的my.cnf或者my.ini

 

sql\_mode=NO\_ENGINE\_SUBSTITUTION,STRICT\_TRANS\_TABLES

1

添加该行就ok!

 

还有一种错也是不兼容的问题导致的

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘nctest.pivot.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql\_mode=only\_full\_group\_by

 

这种问题就是sql\_mode=only\_full\_group\_by导致的，去掉only\_full\_group\_by就解决了