MySQL常見的幾個錯誤匯總

  • 2019 年 10 月 5 日
  • 筆記

參考自:http://www.blogjava.net/xiaomage234/archive/2014/07/25/416200.html

案例1、在線DDL報錯提示日誌空間不足

MySQL 往一張大表添加欄位時報如下錯誤:

ERROR 1799 (HY000) at line 1: Creating index 'PRIMARY' required more than 'innodb_online_alter_log_max_size' bytes of modification log. Please try again. 

解決方法:

我的資料庫為MySQL 5.5版本,innodb_online_alter_log_max_size值為默認大小128M。

mysql> show variables like 'innodb_online_alter_log_max_size';

+——————————————+———————-+

| Variable_name                            | Value                |

+——————————————+———————-+

| innodb_online_alter_log_max_size         | 134217728            |

+——————————————+———————-+

1 rows in set (0.00 sec)

該參數為動態參數且全局的,可通過如下命令加大

mysql> set global innodb_online_alter_log_max_size=402653184;

Query OK, 0 rows affected (0.03 sec)

加到合適大小,我往120G大小表裡添加欄位設置該值4G,成功執行。

案例2、事務日誌文件設置太小:

MySQL日誌:

140306 12:03:25  InnoDB: ERROR: the age of the last checkpoint is 9434024,

InnoDB: which exceeds the log group capacity 9433498.

InnoDB: If you are using big BLOB or TEXT rows, you must set the

InnoDB: combined size of log files at least 10 times bigger than the

InnoDB: largest such row.

應該是Innodb引擎下日誌大小設置過小導致的,某個事物產生大量日誌,但innodb_log_file_size設置過小,可以加大解決。

解決方法:

STEP 01) 修改配置文件 /etc/my.cnf

[mysqld]

innodb_log_buffer_size          = 32M

innodb_buffer_pool_size         = 3G

innodb_log_file_size            = 768M

STEP 02) mysql -uroot -p -e"SET GLOBAL innodb_fast_shutdown = 0;"   # 強制全部內容都執行刷臟到文件中,便於安全關閉資料庫

STEP 03) service mysql stop

STEP 04) rm -f /var/lib/mysql/ib_logfile*

STEP 05) service mysql start

案例3、pt-osc加欄位時候報錯:

收到錯誤如下:

# pt-online-schema-change –alter="add column tag_common text default null" –user=root –password=xxxxxxxx D=MYDB,t=MYTB –execute

Cannot connect to D=lsedata_13Q1,h=10.13.7.47,p=…,u=root

No slaves found.  See –recursion-method if host BJL1-Y13-10-ops.gaoder.net has slaves.

Not checking slave lag because no slaves were found and –check-slave-lag was not specified.

# A software update is available:

#   * Percona Toolkit 2.2.6 has a possible security issue (CVE-2014-2029) upgrade is recommended. The current version for Percona::Toolkit is 2.2.7.

The table `MYDB`.`MYTB` has triggers.  This tool needs to create its own triggers, so the table cannot already have triggers.

這是MYTB表上之前就有觸發器的原因,可以從pt-online-schema-change的工作機制了解到:

1) 如果存在外鍵,根據alter-foreign-keys-method參數值,檢測外鍵相關的表,針對相應的設置進行處理;

2) 創建一個新的表,表結構修改後的數據表,用於從源數據表向新表中導入數據;

3) 創建觸發器,在複製數據開始之後,將對源數據表繼續進行數據修改的操作記錄下來,以便在數據複製結束後執行這些操作,保證數據不會丟失;

4) 複製數據,從源數據表中複製數據到新表中;

5) 修改外鍵相關的子表,根據修改後的數據,修改外鍵關聯的子表;

6) 更改源數據表為old表,把新表更改為源表名,並將old表刪除;

7) 刪除觸發器;