Import MySql dump with progress indicator — Linux

We’ll take the default import command and pipe it through withpv

Image for post
Image for post

In my tests, on a virtual machine with 2–4GB RAM, the ETA timer was pretty accurate for full mysql dumps with filesize of up to 3GB. If the file is larger, the timer can be off by a bit as slowdown happens.

Anyhow, the import was faster than using a typical mysql import.

Before proceeding, make sure you have pv installed on your linux box so we can monitor the progress.

Importing unzipped mysql dump with progress:

# The command
pv ./mysql-dump.sql | mysql -u user -p databasename

# pv — for monitoring the progress
# mysql-dump.sql — the file we want to import
# user — the mysql user
# -p - will ask for the mysql password
# databasename — the mysql database where we want to import the file

When the file starts importing, you’ll see a progress bar and ETA:

1.13GiB 0:15:26 [10MiB/s] [===========================================>   ] 19% ETA 00:05:38

If your file is gzipped, we can pipe that too, no need to extract first:

# notice the added pipe "gunzip"
pv ./mysql-dump.sql.gz | gunzip | mysql -u user -p databasename

Your file will be unzipped and imported on the fly.

I know, it’s not Mr. Robot level, but close enough.

That’s it.

Founder binge.app. Curious dev. Laravel / Angular / VueJs / React Native / Docker. Love stand up shows.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store