There is nice tool called pv

# On Ubuntu/Debian system
$ sudo apt-get install pv # On Redhat/CentOS
$ sudo yum install pv

then e.g. you can use it like this

  pv sqlfile.sql | mysql -u xxx -p xxxx dbname

$ zcat dbpackfile.sql.gz | pv -cN zcat | mysql -uuser -ppass dbname

Please check UPDATE 2 for my latest version

ps: check this blog http://blog.larsstrand.org/2011/12/tip-pipe-viewer.html

UPDATE: seems like above link is broken but I found same article here http://blog.larsstrand.no/2011/12/tip-pipe-viewer.html

UPDATE 2: Even better solution with FULL progress bar. To do it you need to use 2 build in pv options. One is --progress to indicate progress bar and second is --size to tell pv how large the overall file is.

pv --progress --size UNPACKED-FILE-SIZE-IN-BYTES

..the problem is with .gz original file size. You need somehow get unpacked original file size information without unpacking it self, otherwise you will lost our precious time to unpack this file twice (first time pv and second time zcat). But fortunately you have gzip -l option that contain uncompressed information about our gziped file. Unfortunattly you have it in table format so you need to extract before it can be use it. All together can be seen below:

gzip -l /path/to/our/database.sql.gz | sed -n 2p | awk '{print $2}'

Uff.. so the last thing you need to do is just combine all together.

zcat /path/to/our/database.sql.gz | pv --progress --size `gzip -l %s | sed -n 2p | awk '{print $2}'` | mysql -uuser -ppass dbname

To make it even nicer you can add progres NAME like this

zcat /path/to/our/database.sql.gz | pv --progress --size `gzip -l %s | sed -n 2p | awk '{print $2}'` --name '  Importing.. ' | mysql -uuser -ppass dbname

Final result:

Importing.. : [===========================================>] 100%

=================================================================
#sudo yum install pv
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.neu.edu.cn
 * extras: mirror.neu.edu.cn
 * updates: mirror.neu.edu.cn
Setting up Install Process
No package pv available.
Error: Nothing to do
------------------------------------------------------------------
http://wiki.centos.org/AdditionalResources/Repositories/RPMForge#head-f0c3ecee3dbb407e4eed79a56ec0ae92d1398e01
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -K rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
pm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum install pv
=================================================================


ref:
http://www.ivarch.com/programs/pv.shtml

http://unix.stackexchange.com/questions/36769/get-a-progress-indicator-when-importing-mysql-databases
https://major.io/2010/11/24/monitor-mysql-restore-progress-with-pv/
http://dba.stackexchange.com/questions/17367/how-can-i-monitor-the-progress-of-an-import-of-a-large-sql-file
http://www.commandlinefu.com/commands/view/5884/import-sql-into-mysql-with-a-progress-meter

Import SQL into MySQL with a progress meter的更多相关文章

  1. go database/sql sql-driver/mysql 操作

    这里使用的是github.com/Go-SQL-Driver/MySQL, 所以需要下载一个github.com/Go-SQL-Driver/MySQL 引入 database/sql 和 githu ...

  2. sql 笔记(mysql)

    Windows 安装mysql(zip包) 1,zip包解压到要安装目录 2,配置环境变量,Path后加mysql路径\bin 3,修改配置文件,mysql目录下my-default.ini base ...

  3. Java与SQL Server, MySql, Oracle, Access的连接方法以及一些异常解决

    Java与SQL Server, MySql, Oracle, Access的连接方法以及一些异常解决 I. 概述 1.1 JDBC概念 JDBC(Java Database Connectivity ...

  4. 全国省市级联数据sql语句 mysql版

    全国省市级联数据sql语句 mysql版 --省级 provincial create table provincial ( provincialID int, provincialName ), p ...

  5. SQL Server | Mysql 对表的unique 的实现方式

    在ANSI SQL 标准中unique 有两种实现方式 1.是可以插入多个空值.也就是说多个null值看成是互不相同的. 2.是只可以插入一个空值,也主是说把所有的空值看也是相同的. 在SQL Ser ...

  6. 数据库管理工具神器-DataGrip,可同时管理多个主流数据库[SQL Server,MySQL,Oracle等]连接

    前言 DataGrip:Jet Brains出品的一款数据库管理工具(没错,是Jet Brains出品,必属精品).DataGrip整合集成了当前主流数据库(如:SQL Server, MySQL, ...

  7. SQL优化 MySQL版 - B树索引详讲

    SQL优化 MySQL版  - -B树索引详讲 作者:Stanley 罗昊 [转载请注明出处和署名,谢谢!] 为什么要进行SQL优化呢?很显然,当我们去写sql语句时: 1会发现性能低 2.执行时间太 ...

  8. SQL优化 MySQL版 -分析explain SQL执行计划与笛卡尔积

    SQL优化 MySQL版 -分析explain SQL执行计划 作者 Stanley 罗昊 [转载请注明出处和署名,谢谢!] 首先我们先创建一个数据库,数据库中分别写三张表来存储数据; course: ...

  9. SQL优化 MySQL版 - 索引分类、创建方式、删除索引、查看索引、SQL性能问题

    SQL优化 MySQL版  - 索引分类.创建方式.删除索引.查看索引.SQL性能问题 作者 Stanley 罗昊 [转载请注明出处和署名,谢谢!] 索引分类 单值索引 单的意思就是单列的值,比如说有 ...

随机推荐

  1. Exchange OAB(Offline Address Book)

    If Outlook is left running constantly in Cached Exchange Mode, it updates the Offline Address Book a ...

  2. wordpress 忘记密码

    update wp_users set user_pass=md5("123456") where user_login='帐号';

  3. [LeetCode] 1.Two Sum - Swift

    1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...

  4. Storm-源码分析- Component ,Executor ,Task之间关系

    Component包含Executor(threads)的个数 在StormBase中的num-executors, 这对应于你写topology代码时, 为每个component指定的并发数(通过s ...

  5. IE8数组不支持indexOf方法的解决办法

    在使用indexof方法之前加上以下代码就可以了. if (!Array.prototype.indexOf){           Array.prototype.indexOf = functio ...

  6. SpringBoot 之数据访问

    1. Spring Boot 与 JDBC 默认使用 org.apache.tomcat.jdbc.pool.DataSource 数据源; // application.yml spring: da ...

  7. python pip命令技巧

    确保本地开发环境,和线上一致性 1.导出当前解释器的模块pip3 freeze > requirements.txt 2.将这个文件requirements.txt,上传至服务器,在新的虚拟环境 ...

  8. JSON 序列化与反序列化(二)使用TypeReference 构建类型安全的异构容器

    1. 泛型通常用于集合,如Set和Map等.这样的用法也就限制了每个容器只能有固定数目的类型参数,一般来说,这也确实是我们想要的. 然而有的时候我们需要更多的灵活性,如数据库可以用任意多的Column ...

  9. java 多线程 day14 Semaphore 线程信号灯

    import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.c ...

  10. thread msg

    提取的nordic rf51xx/rf52xx sdk中的线程间消息通信机制,非常简洁 demo.c #include <stdio.h> #include <stdlib.h> ...