How to import a compressed SQL backup to MySQL/MariaDB database

This method should be used for importing large databases on cPanel servers or on servers that don't have cPanel or phpMyAdmin. Keep in mind that phpMyAdmin requires you to configure the PHP version to allow large file uploads and PHP execution time. By uploading a compressed SQL file directly to MySQL or MariaDB, you won't rely on PHP. This is the most reliable method of importing databases.

To do this, you will use the zcat utility and pipe this into the mysql program.

zcat database_dump.sql.gz | mysql -u user -p database

For example, this command may look like:

zcat mydatabase.sql.gz | mysql -u mydbuser -p mydatabase

You would run this from where the mydatabase.sql.gz file is located or provide the direct path to it. Switch mydbuser and mydatabase for the appropriate values. When you press enter, you will be prompted to enter the password for the database user.

Linux Linux Tip: the pipe command ( | ) redirects the output of one program and uses it as input for another. This is different from redirecting output ( > ) or input ( < ) as the zcat program will output a compressed file like the cat program will output a regular file.

 

Article Information
  • Article ID: 358
  • Category: Databases
  • Viewed 257 times.
  • Rating:
    (0)
  • Was this article helpful?
  • Yes No
Did you find this article helpful?