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 罗昊 [转载请注明出处和署名,谢谢!] 索引分类 单值索引 单的意思就是单列的值,比如说有 ...
随机推荐
- http请求及json发送与解析 post string
golang http请求及json流解析 - 长风v持成的博客 - CSDN博客 https://blog.csdn.net/u011677067/article/details/80852158 ...
- BitTrex行情查看与技术指标系统
上个月的时候,向TradingView申请K线图行情插件,填了各种资料,被问了N多问题,结果却仍是不愿意提供插件给我们. 于是,我们自己开发了一个BitTre行情查看与技术指标系统, 这套系统被国内多 ...
- 解决MySQL ERROR 1130 (HY000): Host '192.168.31.115' is not allowed to connect to this MariaDB server
# 给root用户授权 GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.31.115' IDENTIFIED BY 'root' WITH GRANT O ...
- matplotlib的一些代码
Matplotlib Python 画图教程 (莫烦Python)_演讲•公开课_科技_bilibili_哔哩哔哩 https://www.bilibili.com/video/av16378354/ ...
- mysql相关配置
http://www.cnblogs.com/cnblogsfans/archive/2009/09/21/1570942.html http://www.jb51.net/article/31902 ...
- By.Xpath快速定位页面元素常用方法
先看一看xpath的语法 我们将在下面的例子中使用这个 XML 文档. <?xml version="1.0" encoding="ISO-8859-1" ...
- 微信小程序组件switch
表单组件switch:官方文档 Demo Code: Page({ switch1Change: function (e){ console.log('switch1 发生 change 事件,携带值 ...
- java反射子之获取方法信息(二)
一.获取方法 1.方法作用. 2. 二.获取方法信息.(修饰符,返回值,方法名称,参数列表,抛出的异常). ############################################## ...
- filebeat+logstash通过zabbix微信报警
一.安装软件: 1.在要收集日志的机器上安装filebeat: 1).下载安装: cd /usr/local/src wget https://artifacts.elastic.co/downloa ...
- GIt-远程仓库(特性)
本人拜读了廖雪峰老师关于Git的讲述后整理所得 上一节讲的Git在一个仓库中对于文件进行基本管理和这种和SVN的功能类似, 如果只是在一个仓库里管理文件历史,Git和SVN真没啥区别,并没有体现出Gi ...