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 罗昊 [转载请注明出处和署名,谢谢!] 索引分类 单值索引 单的意思就是单列的值,比如说有 ...
随机推荐
- hdu2254 奥运 矩阵的应用
hdu2254 奥运 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2254 题意:题目让我们求得是的可以得到的金牌数量,而和金牌数量=在t1到t2天( ...
- IOS学习笔记48--一些常见的IOS知识点+面试题
IOS学习笔记48--一些常见的IOS知识点+面试题 1.堆和栈什么区别? 答:管理方式:对于栈来讲,是由编译器自动管理,无需我们手工控制:对于堆来说,释放工作由程序员控制,容易产生memor ...
- node jar sh
https://nodejs.org/api/child_process.html Node.js v11.1.0 Documentation Index View on single page Vi ...
- JAVA—List集合总结
List接口总结: List接口是Collection接口的子接口,从其名称可以看出,是一个元素有序(并不是按大小排序,具有顺序索引,类似于数组),默认按照元素的添加顺序设置元素的索引,List和Se ...
- 【react npm】解决用npmstart启动别人的react项目的问题1:sha1-xxx checksum failed wanted sha1-xxx but got sha512-xxx. (10700 bytes)
1.npm是nodejs的包管理器,相当于php的composer,python的pip,用于安装各种包. 2.一般来说,别人拷给你的react项目不会带依赖包的,因为太大了,需要用npm命令自己安装 ...
- Spring Bean声明周期
Bean的生命周期 理解Spring Bean的生命周期很容易.当一个bean被实例化时,它可能需要执行一些初始化使它转换成可用状态.同样,当bean不再需要,并且从容器中移除时,可能需要做一些清除工 ...
- CheckStyle——检查编码格式等是否符合规范
CheckStyle 一.checkstyle简介 checkstyle是idea中的一个插件,可以很方便的帮我们检查java代码中的格式错误,它能够自动化代码规范检查过程,从而使得开发人员从这项重要 ...
- 理解java动态代理
java动态代理是java语言的一项高级特性.在平时的项目开发中,可能很难遇到动态代理的案例.但是动态代理在很多框架中起着不可替代的作用,例如Spring的AOP.今天我们就聊一聊java动态代理的实 ...
- Mediakit报告设备商的空间不足以执行此操作的纯MAC解法
使用Mac对磁盘进行分区,显示“Mediakit报告设备商的空间不足以执行此操作”,该怎么办? What 买了一个4TB的移动硬盘,准备进行分区给Time Machine用. 硬盘自带是HDFS的,所 ...
- k8s-离线安装coreos
1.安装准备 下载iso 前往页面https://coreos.com/os/docs/latest/booting-with-iso.html 版本:stable 1465.7.0 日期:2017. ...