If you have permission to use the exec system calls, you can do something like the following
exec("mysql -u".$DB_USER." --password='".$DB_PASS."' -e 'DROP DATABASE IF EXISTS `".$NEW_DB."`; CREATE DATABASE `".$NEW_DB."`;'"); exec("mysqldump -u".$DB_USER." -p'".$DB_PASS."' ".$EXISTING_DB." | mysql -u ".$DB_USER." --password='".$DB_PASS."' ".$NEW_DB);
This will drop $ NEW_DB, if present, and recreate it, and then flush all tables and data from $ EXISTING_DB to $ NEW_DB
Denial of responsibility. It is generally not recommended to pass your mysql password on the command line. I'm not sure, but I would suggest that this could probably be seen by someone with root privileges, who has the ability to view all the processes and command line options that started them.
In addition, from the point of view of your other question on how to create a table in a new database with columns corresponding to others, you can use the following SQL
CREATE TABLE new_database.new_table LIKE old_database.old_table
source share