We help IT Professionals succeed at work.

mysql import from a .zip on Ubuntu

dolythgoe
dolythgoe asked
on
Hello all,

Please could someone help me with the command I need in Ubuntu 11 CLI for importing a .zip into the mysql?

The .zip file contains a CREATE DATABSE.

Cheers
Comment
Watch Question

Nem SchlechtIT Supervisor
CERTIFIED EXPERT
Top Expert 2009

Commented:
'unzip' your file and then feed the resulting SQL statements into a 'mysql' connection (assuming you have CREATE DATABASE privileges).

Let's say your ZIP file contains a single file, 'dbscheme.sql'.  Extract that out of the ZIP file and then run, on the command line:
mysql --username=mysql_username -p < dbscheme.sql

Open in new window

And enter your password when prompted.  This assumes that you're connecting to MySQL on your localhost, if not, just add '-h hostnmae'.

Author

Commented:
Thanks for that but isn't there a way to do it straight from zip? ie. unzip and import in one statement?
IT Supervisor
CERTIFIED EXPERT
Top Expert 2009
Commented:
Usually I would say no, because a ZIP file isn't like a .gz (GZIP) file, it's like a .tar.gz - the issue being that any sort of command to output the contents of the ZIP file would usually also contain filenames, permissions, checksums, etc.

However, 'unzip' does let you do this - use the '-p' option to pipe the output (without any messages) into MySQL:

unzip -p dbschema.zip dbschema.sql | mysql -u username -p

Open in new window


Where 'dbschema.zip' is the ZIP file and 'dbschema.sql' is the SQL file in that ZIP file.

Author

Commented:
Great thanks for your help :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.