Posts

How do I load a sql.gz file to my database? (importing)

Many of us use phpmyadmin to utilize any sort of importing and exporting of MySQL databases. But what if there was an easier way and faster solution. You will need SSH access to your VPS or dedicated server box. Its a one liner:

zcat /path/to/file.sql.gz | mysql -u ‘root’ -p ‘password’ your_database

zcat = decompresses the data of all the input files, and writes the result on the standard output. zcat concatenates the data in the same way cat does. The names of compressed input files are expected to end in .Z, .gz, or .bz2.

path = you must know full path of your sql file

-u username = in this example we are using root as the username, however you can use a username of your particular mysql that you are importing.

-p = is the password for your username above

your_database = name of the database where you are importing your sql.gz file.

That’s it, fairly simple. If you run into any issues don’t hesitate to contact us.