Case: You have successfully connected to a MySQL/MariaDB database. But when trying to import a large SQL file, an error occurred.
Error Code: 2013. Lost connection to MySQL server during query
Reason:
- Timeout due to slow connection or too much data (Not the server's fault)
- Memory allocated is not enough: the data fields are too large ....
Quick fix:
Increase memory for Mysql package.
Find config file
Eg:
Xampp Windows: C:\xampp\mysql\bin\my.iniLinux: /etc/my.cnf
Edit file my.ini (my.cnf), find [mysqld] block, to change max_allowed_packet to a larger value (16, 32, or 128 M)
Eg:
[mysqld]
.....
max_allowed_packet=128M
Then restart MySQL
*Note:
- If max_allowed_packet is not found, you can add it to your [mysqld] block yourself.
- Increasing memory capacity may affect the stability of MySQL server. So you can freely change it on your local computer, but if you are on the product server, please consider carefully. Another solution to importing large mysql files on the server is to use the command line.
Done ! Solved !