Error Code: 2013. Lost connection to MySQL server during query

后端 未结 29 1886
深忆病人
深忆病人 2020-11-22 16:22

I got the Error Code: 2013. Lost connection to MySQL server during query error when I tried to add an index to a table using MySQL Workbench. I noticed als

相关标签:
29条回答
  • 2020-11-22 16:26

    If your query has blob data, this issue can be fixed by applying a my.ini change as proposed in this answer:

    [mysqld]
    max_allowed_packet=16M
    

    By default, this will be 1M (the allowed maximum value is 1024M). If the supplied value is not a multiple of 1024K, it will automatically be rounded to the nearest multiple of 1024K.

    While the referenced thread is about the MySQL error 2006, setting the max_allowed_packet from 1M to 16M did fix the 2013 error that showed up for me when running a long query.

    For WAMP users: you'll find the flag in the [wampmysqld] section.

    0 讨论(0)
  • 2020-11-22 16:27

    Go to Workbench Edit → Preferences → SQL Editor → DBMS connections read time out : Up to 3000. The error no longer occurred.

    0 讨论(0)
  • 2020-11-22 16:29

    Add the following into /etc/mysql/cnf file:

    innodb_buffer_pool_size = 64M
    

    example:

    key_buffer              = 16M
    max_allowed_packet      = 16M
    thread_stack            = 192K
    thread_cache_size       = 8
    innodb_buffer_pool_size = 64M
    
    0 讨论(0)
  • 2020-11-22 16:30

    Go to:

    Edit -> Preferences -> SQL Editor

    In there you can see three fields in the "MySQL Session" group, where you can now set the new connection intervals (in seconds).

    0 讨论(0)
  • 2020-11-22 16:32

    I faced this same issue. I believe it happens when you have foreign keys to larger tables (which takes time).

    I tried to run the create table statement again without the foreign key declarations and found it worked.

    Then after creating the table, I added the foreign key constrains using ALTER TABLE query.

    Hope this will help someone.

    0 讨论(0)
  • 2020-11-22 16:32

    There seems to be an answer missing here for those using SSH to connect to their MySQL database. You need to check two places not 1 as suggested by other answers:

    Workbench Edit → Preferences → SQL Editor → DBMS

    Workbench Edit → Preferences → SSH → Timeouts

    My default SSH Timeouts were set very low and causing some (but apparently not all) of my timeout issues. After, don't forget to restart MySQL Workbench!

    Last, it may be worth contacting your DB Admin and asking them to increase wait_timeout & interactive_timeout properties in mysql itself via my.conf + mysql restart or doing a global set if restarting mysql is not an option.

    Hope this helps!

    0 讨论(0)
提交回复
热议问题