简体   繁体   中英

MySQL server has gone away - shared account

I'm trying to do the following but keep getting "MySQL server has gone away"

  1. Read approx 100,000 rows from an informix db (each row approx 400 chars). No issues with this
  2. Insert the 100,000 rows into a MySQL table hosted on shared hostgator acct

I received "MySQL server has gone away" and then updated my INSERT to use one INSERT command

Ex: $queryMySQL = INSERT into table (field1, field2, field3,...) values ('A', '2017-02-01', ..), ('B', '2017-02-01', ..), ('C', '2017-02-01', ...),...'

This didn't work so I tried opening a persistant connection ini_set('mysqli.reconnect', 'on') ; and $db_mysqli = new mysqli('p:'.$host, $Username,$Pswd,$database);

This didn't help so I tried inserting 50,000 instead of 100,000 (which i prefer not to do) but still get MySQL server has gone away

Since this is a shared hostgator account, I don't have access to php.ini nor mysql.cnf

Any suggestions ?

Why it happened

You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld gets a packet that is too large. or out of order, it assumes that something has gone wrong with the client and closes the connection.

What can be done

The easy way to avoid this problem is to ensure that max_allowed_packet is set bigger in the mysqld server than in the client and that all clients uses the same value for max_allowed_packet.

What you can do??

Since you're already using a hosting, ask the hosting support to fix the issue. Well if they cannot and you can reduce the query size reduce it, and if it doesn't solve your issue, trying changing the hosting.

MYSQL Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM