'How to prevent ERROR 2013 (HY000) using Aurora Serverless
When performing long-running queries on Aurora Serverless I have seen the following errors after a few minutes:
- ERROR 1080 (08S01) Forcing close of thread
- ERROR 2013 (HY000) Lost connection to MySQL server during query
The queries are using mysql LOAD DATA LOCAL INFILE to load large (multi-GB) data files into the database.
How can I avoid these errors?
Solution 1:[1]
To solve this, you can change the parameter group item net_write_timeout to a more suitable value. Here's instructions for completing the steps from the console:
- Go to RDS Console
- Click "Parameter Groups" in the left pane
- Click "Create Parameter Group"
- On the Parameter Group Details page, for Type, choose DB Cluster Parameter Group; then give it a name and description, and click "Create"
- Click on the name of the parameter group you created in step 4
- Search for "net_write_timeout"
- Click on the checkbox next to the parameter and click "Edit Parameters"
- Change the value to an integer between 1-31536000 for the number of seconds you want it to wait before timing out, and click "save changes"
- Click on Databases in the left pane
- Click on the database and click "modify"
- Under Additional Configuration > Database Options > DB Cluster Parameter Group, select the parameter group you created in step 4, and click "Continue"
- Select "Apply Immediately" and click "Modify Cluster"
Solution 2:[2]
Break up your large, multi-GB uploads into smaller chunks. Aurora works better (and faster) loading one hundred 10MB files at once rather than one 1GB file. Assuming your data is already in a loadable format:
- Split the file into parts using
split
split -n l/100 --additional-suffix="_small" big_file.txt
This results in 100 files like xaa_small xab_small, etc.
- find files that match the split suffixes using
find
files=$(find . -name 'x*_small')
- loop through the files and load each in parallel
for file in $files; do
echo "load data local infile '$file' into table my_table;" |
mysql --defaults-file=/home/ubuntu/.my.cnf --defaults-group-suffix=test &
done
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | enharmonic |
| Solution 2 | enharmonic |
