[EN] Track progress of MySQL Import/Export process using PV
![[EN] Track progress of MySQL Import/Export process using PV](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2Fjf1EomjlQi0%2Fupload%2Fa7ee07f61c1dc2ad71b4cf2bb4523765.jpeg&w=3840&q=75)
The problem
Today, I need to export a MySQL database and then import it to a new server. The database is not too big, just a few GBs. But it was taking so long, and I wonder when this will be finished? By default, when you run mysqldump command to export the database and then mysql to import it, it doesn’t show any progress. I'm not sure whether the process is stuck or running.
root@server:~# mysqldump some_database > backup.sql
# Nothing to see here.
# The terminal shows nothing until the process is finished.
The solution
Then I discovered Pipe Viewer (PV). According to the website, Pipe Viewer is:
Pipe Viewer - is a terminal-based tool for monitoring the progress of data through a pipeline and modifying its flow. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion. Data flow rate, error handling strategy, buffer size, and cache interaction can all be adjusted.
Let’s see how it works:
# Install the pv package
root@47be583c9aaf:/# apt update && apt install -y pv
# Let's export a database.
# Using mysqldump, there’s no "total expected size".
# While PV can show progress percentages only when it knows the total size.
# I know the DB size. So I tell PV using the "-s" option.
root@localhost:~# mysqldump some_database | pv --size 3G > some_database.sql
36MiB 0:00:09 [65.8MiB/s] [========> ] 17% ETA 0:00:42
# Now let's import the database
# Now PV know the size of the DB dump, so I don't need the "-s" option.
root@47be583c9aaf:~# pv some_database.sql | mysql -p some_database
5.09GiB 0:06:47 [12.8MiB/s] [==================================>] 100%
Now I don’t have to worry, knowing when it will be finished and the process speed.
PV is not exclusive to MySQL-related activity. But it can also be used for other use cases. Such as monitoring the progress of file compression and decompression, copying a file, and many more.
![[EN] Set Up Amazon ECR Pull-Through Cache for Docker Hub](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fuploads%2Fcovers%2F631dd8693e8d6f3497ad63e7%2F1ca35a5a-6303-4a86-badb-91961cf65694.jpg&w=3840&q=75)
![[EN] Lesson learned from using the wrong AWS ElastiCache Redis endpoint](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FemolMCqnKfg%2Fupload%2Fc7eb8197eb9ef632459ae6612b861cc6.jpeg&w=3840&q=75)
![[EN] My experience taking the KCNA certification](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FKXwPJtAJLfU%2Fupload%2F3deba4b52e1b8e442179a495944ccb9e.jpeg&w=3840&q=75)
![[EN] How I Stopped Copy-Pasting AWS EC2 IPs and Started SSHing Smarter](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fstock%2Funsplash%2FDXRP2PKlsFQ%2Fupload%2F8767e91ce57fa7ff90bca9149c142626.jpeg&w=3840&q=75)