记录一次自己进行大表导入的操作。
需要导入 mysql 20G 的文本文件
直接总结经验如下:
- 直接创建表,不设置主键和索引
- 关闭autocommit自动提交
- 关闭Binlog
//关闭日志
//关闭autocommit自动提交模式 0是关闭 1 是开启(默认)
set sql_log_bin=OFF;
set autocommit=0;
优化处理后,700w 级别数据在 40分钟作用,完成导入。
继续优化,Mariadb 在连续导入的时候会出现Crash的问题。
日志报错如下,看起来像是资源相关的问题。
Server version: 10.4.12-MariaDB-log
key_buffer_size=33554432
read_buffer_size=8388608
max_used_connections=3
max_threads=514
thread_count=9
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 6361464 K bytes of memory
Hope that's ok; if not, decrease some variables in the equation.