首页 > 数据库 >Import SQL into MySQL with a progress meter

Import SQL into MySQL with a progress meter

时间:2023-11-06 15:32:24浏览次数:49  
标签:pv -- into sql http meter SQL progress mysql


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

.sql |-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



标签:pv,--,into,sql,http,meter,SQL,progress,mysql
From: https://blog.51cto.com/emanlee/8213077

相关文章

  • MySQL: Speed of INSERT Statements
    SpeedofINSERTStatementsTooptimizeinsertspeed,combinemanysmalloperationsintoasinglelargeoperation.Ideally,youmakeasingleconnection,sendthedataformanynewrowsatonce,anddelayallindexupdatesandconsistencycheckinguntilthe......
  • jsqlparser v4.6 版本下sql解析报错
    项目版本:springboot2.7.2mybatis-plus3.5.2jsqlparser4.6该版本下mybatis-plus生成的sql文件带有连续\n\n\nCCJSqlParserUtil.parseStatements("select\n\n\n*from\n\ndual\n")再使用jsqlparser进行sql解析时会出现如下报错net.sf.jsqlparser.parser.ParseExc......
  • 记一次centos7安装python的mysql-client
    Exception:Cannotfindvalidpkg-configname.SpecifyMYSQLCLIENT_CFLAGSandMYSQLCLIENT_LDFLAGSenvvarsmanually起初安装发现缺少pkg-config和 MYSQLCLIENT_LDFLAGS环境变量,安装和手动声明环境变量后又报新的错MYSQL_OPT_SSL_ENFORCE......
  • How can I move a MySQL database from one server to another?
     Myfavoritewayistopipeasqldumpcommandtoasqlcommand.Youcandoalldatabasesoraspecificone.So,forinstance,mysqldump-uuser-ppasswordmyDatabase|mysql-hremoteserver-uremoteuser-premoteserverpasswordYoucandoalldatabaseswithmysq......
  • Centos 7 官网下载安装mysql server 5.6
    Centos7官网下载安装mysqlserver#wgethttp://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm#rpm-ivhmysql-community-release-el7-5.noarch.rpm#yuminstallmysql-community-server安装成功后重启mysql服务。#servicemysqldrestart初次安装mysql,root......
  • 处理mysql中in条件大于1000条的问题
    WHERExsfnsrsbhIN<foreachcollection="param.nsrsbhList"index="index"item="nsrsbh"open="("close=")"><iftest="index>0"><choose>......
  • 一次插入多条记录的SQL语句
    在使用SQL数据库的时候,我们也许会需要一次像数据库中添加多条记录,那么我们可以使用SQL语句来实现,该语句具体如下:--添加一条记录    INSERTINTOtableName(col1,col2,col3)VALUES(1,2,3)       --添加多条记录    INSERTINTOtableName(col1,col2,col3)    S......
  • sql数据库文件的迁移mdf操作方法
    http://www.pcxitongcheng.com/shujuku/MsSql/2022-11-11/32457.htmlmdf文件很特殊能接触到他的小伙伴很少,但也还是有不少会遇到关于mdf的问题,今天就给你们带来了数据库mdf文件转换为sql文件的详细方法,一起看看吧。sql数据库文件的迁移mdf:1、打开sqlserver控制台。2、选中要......
  • mysql 大小写问题和非严格模式
    mysql大小写问题mysqlselect语句,我们输入不管大小写都能查询到数据,例如:输入aaa或者aaA、AAA都能查询同样的结果,说明查询条件对大小写不敏感。解决方案一:于是怀疑Mysql的问题。做个实验:直接使用客户端用sql查询数据库。发现的确是大小不敏感。#DDLCREATETABLE`tb_emp`......
  • 231106-jmeter随笔
    1.获取接口的执行时间 Stringctime=prev.getTime().toString();2.String转int intc=Integer.parseInt(ctime);3.获取接口的请求data部分Stringreq_data=prev.queryString4.jmeter后置处理器,文件写入本地,用于帅选参数化数据Stringfilename=“本......