MySQL Error

‘Lock wait timeout exceeded; try restarting transaction’

解决办法:

  • 连接mysql

  • 查询当前连接进程

    1
    show processlist;
  • kill进程

    1
    kill id

1071, ‘Specified key was too long; max key length is 767 bytes’

数据库表采用utf8编码,其中varchar(255)的column进行了唯一键索引,而mysql默认情况下单个列的索引不能超过767位(不同版本可能存在差异),于是utf8字符编码下,255*3 byte 超过限制。

解决方案

  • 使用innodb引擎;
  • 启用innodb_large_prefix选项,将约束项扩展至3072byte;
  • 重新创建数据库;

my.cnf 配置

1
2
default-storage-engine=INNODB
innodb_large_prefix=on

一般情况下不建议使用这么长的索引,对性能有一定影响;

Too many keys specified; max 64 keys allowed

这是因为 MySQL 默认最大允许在一个表中建立 64 个索引,一般情况表的索引数量是不会超过 64 个的

this is incompatible with sql_mode=only_full_group_by

SQL语句查看MySQL配置

1
2
SELECT @@GLOBAL.sql_mode;
SELECT @@SESSION.sql_mode;

输出结果

1
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

解决方案

  • 只选择出现在group by后面的列,或者给列增加聚合函数;

  • 默认关掉ONLY_FULL_GROUP_BY

1
2
3
set sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
# or
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));3

The table ‘*’ is full; nested exception is java.sql.SQLException

  1. 查看当前空间情况
1
SHOW VARIABLES WHERE Variable_name LIKE '%table_size%'

输出结果

1
2
3
4
5
6
+---------------------+----------+  
| Variable_name | Value |
+---------------------+----------+
| max_heap_table_size | 16777216 |
| tmp_table_size | 16777216 |
+---------------------+----------+

相关配置

1
2
3
[mysqld]  
tmp_table_size = 32M
max_heap_table_size = 32M
  1. 另外设置

innodb_data_file_path=ibdata1:10M:autoextend:max:512M

  1. Disk is full writing ‘./master-bin.~rec~’ (Errcode: -2061346848 - No space left on device). Waiting for someone to free space…

参考链接:https://dba.stackexchange.com/questions/43503/how-to-solve-the-table-is-full-with-innodb-file-per-table