Import MySql dump with progress indicator — Linux

Dejan Blazeski
Sep 9, 2019 · 2 min read

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

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.

Dejan Blazeski

Written by

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

More From Medium

Related reads

Related reads

DevTools recap

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade