Search code examples
mariadbmariadb-10.1

Restoring to mariadb10.1 fails the first time, but succeeds when restoring again after recreating the database


I am upgrading from mariadb5.5 to 10.1. I'm trying to restore the dump file output from 5.5 to 10.1, but I'm suffering from the phenomenon that the first restore always fails, and the restore succeeds after deleting and recreating the database. The content of the error is

ERROR 1449 (HY000) at line 44811: The user specified as a definer ('batch'@'localhost') does not exist

But 'batch'@'localhost' does exist and indeed a second restore succeeds with the same dump file without adding the user. The commands I'm actually using are:

// in mariadb5.5
$ mysqldump -u root -p -x -h localhost -R --opt --quick databasename | gzip > /root/backup_db/databasename.sql.gz
$ mysqldump -u root -p -x -h localhost --allow-keywords mysql | gzip > /root/backup_db/mysql.sql.gz

// After installing mariadb10.1
$ mysql_secure_installation
$ mysql_upgrade -u root -p
$ mysql -u root -p -h localhost
# create database databasename;
# \q
// After decompressing the compressed dump file
$ mysql -u root -p -h localhost mysql < mysql.sql
$ mysql -u root -p -h localhost databasename< databasename.sql // always fails here

$ mysql -u root -p -h localhost
# drop database databasename;
# create database databasename;
# \q

$ mysql -u root -p -h localhost databasename< databasename.sql // success here

Please let me know if there are any possible causes or things to check. Thank you.

Thinking that net_buffer_length is insufficient,

net_buffer_length=1024000 

I tried to restore by changing to , but it failed. Max_allowed_packet at that time was

max_allowed_packet=100MB.


Solution

  • When restoring a dump of a mysql database taken separately (as opposed to --all-databases which does special handling), a FLUSH PRIVILEGES is needed to restore that dump to the running configuration of the database.

    The mysql_upgrade, now called mariadb-upgrade in 10.4+, alters the mysql.* tables to correspond to the new features of the mariadb version and issues a FLUSH PRIVILEGES.

    So when restoring to a new major version, run mysql_upgrade after restoring the mysql database. If restoring to the same version, a FLUSH PRIVILEGES after restoration is sufficient.