导入服务器数据库表报1153 - Got a packet bigger than 'max_allowed_packet' bytes问题

本地数据库表结构导入服务器数据库报1153 - Got a packet bigger than 'max_allowed_packet' bytes问题:


Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1050 > 1024). You can change this value on the server by setting the max_allowed_packet' variable.
; SQL []; Packet for query is too large (1050 > 1024). You can change this value on the server by setting the max_allowed_packet' variable.; nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1050 > 1024). You can change this value on the server by setting the max_allowed_packet' variable.
大概意思是权限全局可写,任何一个用户都可以写。mysql担心这种文件被其他用户恶意修改,所以忽略掉这个配置文件。导致无法进入,这也是mysql的安全机制之一。所以我们必须得改一些权限。设置其他用户不可写

解决办法1:


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> mysql -u root -p 

mysql> 输入密码

mysql> select @@global.max_allowed_packet; 


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

| @@global.max_allowed_packet |
+-----------------------------+
|                        1024 |
+-----------------------------+
1 row in set (0.00 sec)


mysql> set global max_allowed_packet = 2*1024*1024*10         #修改配置
    -> ;
Query OK, 0 rows affected (0.00 sec)


mysql> select @@global.max_allowed_packet;
+-----------------------------+
| @@global.max_allowed_packet |
+-----------------------------+
|                    20971520 |
+-----------------------------+
1 row in set (0.00 sec)


mysql> exit;


解决方法2:


(1) 查看my.cnf文件的权限:ls -l /etc/my.cnf
信息如下:
cryhelyxx@ada:~$ ls -l /etc/my.cnf
-rw-r--r-- 1 root root 1126  4月 13 16:46 /etc/my.cnf
cryhelyxx@ada:~$ 
可以看到my.cnf文件权限为644, 如果你的my.cnf文件权限不是"-rw-r--r--", 而是如“-rwxrwxrwx”等等, 则执行以下命令:
sudo chmod 644 /etc/my.cnf


例:
查看权限:
[root@localhost ~]# ls -l /etc/my.cnf


-rwxr-xrwx 1 root root 1091 Nov  9 10:03 /etc/my.cnf


授权644:
[root@localhost ~]# sudo chmod 644 /etc/my.cnf


重启服务:
[root@localhost ~]# service mysqld restart


Redirecting to /bin/systemctl restart  mysqld.service


进入MySQL:
[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.33 MySQL Community Server (GPL)


Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
查看配置信息
mysql> select @@global.max_allowed_packet;
+-----------------------------+
| @@global.max_allowed_packet |
+-----------------------------+
|                    52428800 |
+-----------------------------+
1 row in set (0.00 sec)


mysql> exit;
Bye




参考:

http://blog.sina.com.cn/s/blog_56d8ea9001012un7.html

http://blog.csdn.net/java_mr_zheng/article/details/50469203

//授权my.cnf
http://blog.csdn.net/xeay123/article/details/44127951


3. mysql max_allowed_packet 修改后又还原
   3.1 修改mysql root 账号密码
   查看日志参考: http://www.2cto.com/database/201304/203073.html

你可能感兴趣的:(Mysql,mysql)