All I want to do is create a new database off of a dump created by phpmyadmin.
This dump is located in : /var/www/iadmin/wikifresh/db/template.sql and won’t ever change.
I ran this command once, and the database was created fine
mysql test < /var/www/iadmin/wikifresh/db/template.sql
and it created the database. So, I put that script inside of a php exec command:
(note: $wikiname is the name of the new wiki being created)
$dbwikiname = escapeshellarg($wikiname);
exec("mysql $dbwikiname < /var/www/iadmin/wikifresh/db/template.sql");
now, when this script runs, I get:
ERROR 1049 (42000): Unknown database 'test'
even if I try to run it from my command line I have this issue.
what am I doing wrong?
For
mysqlto be invoked with a default database name, the database must exist.Some distributions of MySQL happen to ship with a database called
test, which explains why your command succeeded at first. One presumes you have since dropped that database? You will need to recreate it before attempting to select it:Of course, you could instead place the above command, followed by
USE test;atop yourtemplate.sqlfile and then invokemysqlwithout specifying a default database.