Mysql restore db with error “MySQL server has gone away”

  linux

Set up database:

CREATE DATABASE confluence_db CHARACTER SET utf8 COLLATE utf8_bin;
create user 'confluence_user'@'%' identified by 'PASSWORD GOES HERE';
grant all privileges on confluence_db.* to 'confluence_user'@'%';

Import from file:

mysql -u confluence_user -p confluence_db < ./confluence.sql

Or: you can install pv to watch the progress:

apt-get install pv
pv confluence.sql | mysql -uconfluence_user -pMYPASSWORD confluence_db

If you get this error:

ERROR 2006 (HY000) at line 2958: MySQL server has gone away

then:

# Go in as root and change max_allowed_packet
sudo su
mysql -u root -p

# check the max:
show variables like 'max_allowed_packet';

# change it
SET GLOBAL max_allowed_packet=1073741824;

# exit
exit

# check that it sticks
mysql -u root -p
show variables like 'max_allowed_packet';


# Run the import again.