Import SQL into MySQL with a progress meter
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的更多相关文章
- go database/sql sql-driver/mysql 操作
这里使用的是github.com/Go-SQL-Driver/MySQL, 所以需要下载一个github.com/Go-SQL-Driver/MySQL 引入 database/sql 和 githu ...
- sql 笔记(mysql)
Windows 安装mysql(zip包) 1,zip包解压到要安装目录 2,配置环境变量,Path后加mysql路径\bin 3,修改配置文件,mysql目录下my-default.ini base ...
- Java与SQL Server, MySql, Oracle, Access的连接方法以及一些异常解决
Java与SQL Server, MySql, Oracle, Access的连接方法以及一些异常解决 I. 概述 1.1 JDBC概念 JDBC(Java Database Connectivity ...
- 全国省市级联数据sql语句 mysql版
全国省市级联数据sql语句 mysql版 --省级 provincial create table provincial ( provincialID int, provincialName ), p ...
- SQL Server | Mysql 对表的unique 的实现方式
在ANSI SQL 标准中unique 有两种实现方式 1.是可以插入多个空值.也就是说多个null值看成是互不相同的. 2.是只可以插入一个空值,也主是说把所有的空值看也是相同的. 在SQL Ser ...
- 数据库管理工具神器-DataGrip,可同时管理多个主流数据库[SQL Server,MySQL,Oracle等]连接
前言 DataGrip:Jet Brains出品的一款数据库管理工具(没错,是Jet Brains出品,必属精品).DataGrip整合集成了当前主流数据库(如:SQL Server, MySQL, ...
- SQL优化 MySQL版 - B树索引详讲
SQL优化 MySQL版 - -B树索引详讲 作者:Stanley 罗昊 [转载请注明出处和署名,谢谢!] 为什么要进行SQL优化呢?很显然,当我们去写sql语句时: 1会发现性能低 2.执行时间太 ...
- SQL优化 MySQL版 -分析explain SQL执行计划与笛卡尔积
SQL优化 MySQL版 -分析explain SQL执行计划 作者 Stanley 罗昊 [转载请注明出处和署名,谢谢!] 首先我们先创建一个数据库,数据库中分别写三张表来存储数据; course: ...
- SQL优化 MySQL版 - 索引分类、创建方式、删除索引、查看索引、SQL性能问题
SQL优化 MySQL版 - 索引分类.创建方式.删除索引.查看索引.SQL性能问题 作者 Stanley 罗昊 [转载请注明出处和署名,谢谢!] 索引分类 单值索引 单的意思就是单列的值,比如说有 ...
随机推荐
- Servlet------>ServletConfig和ServletContext
原理图: 之一--------->servletConfig 有些时候,有些参数不适合写死,而且初始化servlet要用,可以通过这个头来调用servletConfig 例如:serlet数据库 ...
- 【MongoDB】从入门到精通mongdb系列学习宝典,想学mongodb小伙伴请进来
最近一段时间在学习MongoDB,在学习过程中总共编写了四十余篇博客.从mongodb软件下载到分片集群的搭建. 从理论讲解到实例练习.现在把所有博客的内容做个简单目录,方便阅读的小伙伴查询. 一. ...
- 多线程入门-第五章-线程的调度与控制之yield
yield与sleep类似,只是不能指定暂停多长时间,并且只能让同优先级的线程有执行的机会,让位时间不固定. /* yield使用 */ public class ThreadTest04 { pub ...
- 网络编程 - 1.简单的套接字通信/2.加上通信循环/3.bug修复/4.加上链接循环/5.模拟ssh远程执行命令
1.简单的套接字通信 服务端 ''' 服务端 接电话 客户端 打电话 1.先启动服务端 2.服务端有两种套接字 1.phone 用来干接收链接的 2.conn 用来干收发消息的 ''' import ...
- Django 框架之视图函数(Views)
http请求中产生的两个核心对象: http请求: HttpRequest对象 http响应: HttpResponse对象 所在位置: django.http HttpRequest 对象的属性和方 ...
- 具体解释linux下的串口通讯开发
串行口是计算机一种经常使用的接口,具有连接线少.通讯简单,得到广泛的使用.经常使用的串口是RS-232-C接口(又称EIA RS-232-C)它是在1970年由美国电子工业协会(EIA)联合贝尔系统. ...
- python web框架 django 练习1 django 1.11版本
django练习 在我自己项目里创建一个xiaoliu的文件夹 里面创建s1.py 文件 s1.py文件 里面写各种函数 from django.shortcuts import HttpRespon ...
- Linux打包压缩与安装卸载
一.打包压缩 (1)tar:打包拆包命令 tar -cxzjvf 打包后的文件 欲打包的目录 -c:打包文件夹 -x:拆开文件夹 -z:以gzip格式压缩,默认压缩倍数为6倍 -j:以bzi ...
- 如何看MFC程序
一直以来 我都一个疑惑 如果看懂别人的MFC 程序. 今日忽然略有小悟. Q:MFC是啥? A:MFC是类库.. ************* Q :MFC 啥玩意类库? A;MFC 是封装API的类 ...
- javascript 中的 parameter vs arguments
像往常一样简单粗暴地看码: A parameter is the variable which is part of the method’s signature (method declaratio ...