Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Import gzipped sql using Drush
gunzip -c database.sql.gz | drush sqlc
@alvar0hurtad0

This comment has been minimized.

Copy link

@alvar0hurtad0 alvar0hurtad0 commented Apr 18, 2020

drush sqlq --file=db.sql.gz

@alesrebec

This comment has been minimized.

Copy link

@alesrebec alesrebec commented Oct 8, 2020

drush sqlq --file=db.sql.gz works, but make sure you drop the database first, else it might result with an error on import.
So the full command would be:

drush sql-drop && drush sqlq --file=db.sql.gz

You are still prompted for confirmation before it starts deleting tables.

@siliconmeadow

This comment has been minimized.

Copy link

@siliconmeadow siliconmeadow commented Feb 18, 2021

Even shorter option:

zcat database.sql.gz | drush sqlc

😄

@siliconmeadow

This comment has been minimized.

Copy link

@siliconmeadow siliconmeadow commented Feb 18, 2021

drush sqlq --file=db.sql.gz works, but make sure you drop the database first, else it might result with an error on import.
So the full command would be:

drush sql-drop && drush sqlq --file=db.sql.gz

You are still prompted for confirmation before it starts deleting tables.

That doesn't seem to deal with the zipped file though. It didn't for me, anyway.

@alesrebec

This comment has been minimized.

Copy link

@alesrebec alesrebec commented Apr 8, 2021

drush sqlq --file=db.sql.gz works, but make sure you drop the database first, else it might result with an error on import.
So the full command would be:
drush sql-drop && drush sqlq --file=db.sql.gz
You are still prompted for confirmation before it starts deleting tables.

That doesn't seem to deal with the zipped file though. It didn't for me, anyway.

That's because only gzip seems to be supported by drush sql-query (sqlq) command -> https://drushcommands.com/drush-8x/sql/sql-query/ (under --file option)

@jfcartier

This comment has been minimized.

Copy link

@jfcartier jfcartier commented Aug 7, 2021

zcat seems to be the right solution.
I used to use this method :
gunzip < /path/to/file.sql.gz | drush sql-cli --database=default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment