MySQL – Importing large SQL dumps like a boss

If you are doing mysql dumps on large databases you know that at the moment to import the database you have a blank moment where you don’t know how much time is needed to complete the import, and even you don’t know if is importing somthing or not.

I found a couple of months ago a useful command to get a progress bar of the import status in the console.

The command is pv (pipe view), this program uses the data sent over a unix pipe to be able to know the status. You can combine this command with any kind of command that gets the input from an unix pipe. For this particular post I’ll show how to use it with mysql to import a database.

First, install the command using your package manager.

In Linux

  apt-get install pv

On OSX

  brew install pv

Then, once you have the program on your machine, assuming that you have an SQL dump called db.sql you can use

  pv db.sql | mysql -u root -pmypass dbname

Or using drush for Drupal

  pv db.sql | drush sqlc

Then you will have a nice ascii progress bar like in the screenshot

Happy hacking

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.