问题描述
我正在一个大表上创建全文索引(使用命令行),所以我预计它需要很长时间。不幸的是,每次我在一段时间(大约 1 小时)后收到此错误时:
MysqL> CREATE FULLTEXT INDEX ix_fulltext_catalog ON catalog(catalog_content);
ERROR 2013 (HY000): Lost connection to MysqL server during query
然后当我尝试运行任何命令时,它只是重新连接:
MysqL> show variables like 'connect_timeout';
ERROR 2006 (HY000): MysqL server has gone away
No connection. Trying to reconnect...
Connection id: 8
我尝试将许多变量设置为更高的值,但没有帮助。这些是我的价值观:
| Variable_name | Value |
+-----------------------------------------------+--------------------+
| connect_timeout | 172800 |
| disconnect_on_expired_password | ON |
| init_connect | |
| max_connect_errors | 100 |
| max_connections | 151 |
| max_user_connections | 0 |
| MysqLx_connect_timeout | 30 |
| MysqLx_max_connections | 100 |
| performance_schema_session_connect_attrs_size | 512 |
| connect_timeout | 172800 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 172800 |
| lock_wait_timeout | 31536000 |
| MysqLx_connect_timeout | 30 |
| MysqLx_idle_worker_thread_timeout | 60 |
| MysqLx_interactive_timeout | 28800 |
| MysqLx_port_open_timeout | 0 |
| MysqLx_read_timeout | 30 |
| MysqLx_wait_timeout | 28800 |
| MysqLx_write_timeout | 60 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 60 |
| wait_timeout | 172800 |
+-----------------------------------------------+--------------------+
我还检查了 error.log
文件,但根本没有错误!似乎服务器在 1 小时后就“睡着了”,就像后台没有发生任何事情一样。有人可以帮忙吗?
编辑:正如@danblack 所建议的,我尝试使用 dmesg
并且它显示我的内存不足。
Out of memory: Killed process 489295 (MysqLd) total-vm:12674556kB,anon-RSS:10791368kB,file-RSS:0kB,shmem-RSS:0kB,UID:126 pgtables:21724kB oom_score_adj:0
解决方法
由于 OOM:
选项 1:
在添加索引期间减少innodb_buffer_pool_size
(在线)。
选项 2:
使用另一个全文搜索实现而不是 MySQL。 Solr、Sphinx-search 等用于文本搜索的专用应用程序可以更好地进行直观搜索。
(免责声明我只使用过早于 MySQL-8.0 的版本)。