Import SQL into MySQL with a progress meter
2015-06-22 10:19
639 查看
There is nice tool called
then e.g. you can use it like this
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
..the problem is with
Uff.. so the last thing you need to do is just combine all together.
To make it even nicer you can add progres NAME like this
Final result:
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
pvoptions. One is
--progressto indicate progress bar and second is
--sizeto tell
pvhow large the overall file is.
pv --progress --size UNPACKED-FILE-SIZE-IN-BYTES
..the problem is with
.gzoriginal 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
pvand second time
zcat). But fortunately you have
gzip -loption 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
相关文章推荐
- mysql 分库分表
- Mysql insert声明优化
- mysql配置文件my-small.ini、my-medium.ini、my-large.ini、my-huge.ini 详解
- Mysql常用命令
- mysql中间件研究(Atlas,cobar,TDDL)
- Ubunt下安装mysql及遇到的问题(怎么解决mysql远程连接报10038的错误)
- MySQL设计规范与性能优化
- 突然想把一生都奉献给MySQL
- MySQL优化之——插入 更新 删除
- MySQL优化之——查询
- mysql查询存储过程和函数、视图、触发器
- MySQL数据库中插入中文出现乱码的解决方案
- MySql语句大全:创建、授权、查询、修改等
- MySQL INSERT语句
- zabbix安装出现的问题
- MySQL 常用运算符
- MySQL与逻辑模块
- 教你如何把excel中的数据导入到Mysql中
- Mybatis深入之初始化过程
- 解决mysql“Access denied for user 'root'@'localhost'”