# Mysql遇到的小問題 分享今天在公司服務上面新增Mysql的column遇到的小問題 情境 --- - 那張資料表目前的資料量大約是 1400W筆資料,用下面的語法看容量大概是31G ```sql select concat(round(sum(DATA_LENGTH/1024/1024/1024), 2), 'GB') as data from information_schema.TABLES where table_schema='xxx' and table_name='share_user'; ``` 步驟 --- 1. 輸入此平平無奇的語法,並苦苦等待了快要1個小時後 ```sql Alter table share_user ADD column os_version varchar(16); ``` 2. mysql吐了這一串error!!!! ``` error 1799 (HY000): Creating index 'PRIMARY' required more than 'innodb_online_alter_log_max_size' bytes of modification log. Please try again. ``` 開始詢問Google大神 --- - [找到了此貼文](https://blog.csdn.net/zyz511919766/article/details/12779437) - 開始思考為甚麼會爆掉勒? - 主要的原因應該是 ==`innodb_sort_buffer_size`== 太大了 - 當開始新增欄位時,`innodb_sort_buffer_size`會持續增加,當`innodb_sort_buffer_size` > `innodb_online_alter_log_max_size`,就會噴上面的error了,噴完之後Mysql會根據 ==`DML`== 裡面的暫存內容回滾資料 - 紀錄一下幾個沒見過的名詞 - DDL: 用於管理和定義資料物件,常見語句有 CREATE、DROP、ALTER - DML: 用於操作資料庫物件中所包含的資料 - innodb_sort_buffer_size: 創建InnoDB索引時,使用到的sort buffer的大小 - innodb_online_alter_log_max_size: 對InnoDB表進行DDL操作時,所使用的臨時日志的最大值 開始解決 --- 1. 換table: 因為主要的問題是資料表過於肥大,所以把該欄位放到另外一張比較瘦的表上 2. 改Mysql設定: 把innodb_online_alter_log_max_size 設大一點 ```sql mysql>show variables like 'innodb_online_alter_log_max_size'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | innodb_online_alter_log_max_size | 134217728 | +----------------------------------+-----------+ mysql>set glbal innodb_online_alter_log_max_size = 268435456 (256M,default=128M) ``` #### 參考: - https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html?spm=a2c4g.11186623.0.0.44a72241iJie0I#sysvar_innodb_online_alter_log_max_size - https://blog.csdn.net/zyz511919766/article/details/12779437
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up