pydata

Keep Looking, Don't Settle

mysql 2006 error: Sign up MySQL Server has gone away when importing large sql file

Recently I build a webpage to apply sentiment analysis for the tweets about Trump and Hillary. The real time tweets were pulled and saved to mysql. There are lots of tweets every second to save so I got the mysql crashed again and again.

The following are some of the errors I got:

  1. MySQL error 2006: mysql server has gone away

after the system run for several hours, this error will pop out in the terminal. I google and got some help like this and MySQL Server has gone away when importing large sql file.

They think the error is because of max_allowed_packet. I have changed my size to 256M but it did not help me a lot. I still get some errors.

this is how I did it:

1.1. find the file that contains max_allowed_packet

find /etc/* -type f  -exec grep -il max_allowed_packet {} \;

the file is /etc/mysql/mysql.conf.d/mysqld.cnf

Figure 1. find max_allowed_packet png

1.2. backup that file

cp  /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.orig

1.3. change the size and save it

vi /etc/mysql/mysql.conf.d/mysqld.cnf

Figure 2. change max_allowed_packet

png

  1. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

This error is also related to writting to mysql. I tried the methos on this help but it does not help me.

2.1. check if mysql is run

ps aux | grep mysql

2.2. start the mysql service

sudo service mysql start
or
sudo /etc/init.d/mysql start

Reference

  1. 2ROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2)ls/how-to-deploy-a-flask-application-on-an-ubuntu-vps)

  2. MySQL error 2006: mysql server has gone away