Importing a .sql or .tar.gz-file into database


I have this handy script which exports a database into a tar.gz-file or a .sql-file. This is done without using phpMyAdmin, since the user it's intended for, has to have it as easy as possible.

It uses:
passthru("mysqldump --opt -h$dbhost -u$dbuser -p$dbpass $dbname >$filename");

Now, is there a way to easily import the .sql or .tar.gz-file?
So, in other words: reinstall the backup of the database that has been made with the mysqldump-script - without using phpMyAdmin?

Any help is appreciated!



You can use "mysql" command-line client for importing data

mysql < file.sql
tar -xzOf file.tar.gz | mysql


Can this be done webbased ? I don't want it to run in a command-line way... basically, the user should locate the file - click a button, and import the data.


You can call command line tools from within php, as you have shown in your first message wink


So this it would look like:

passthru("mysql < file.sql tar -xzOf file.tar.gz | mysql");