Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create multiple Databases in one query line

Is there any way to create multiple databases in a single line of a query?

Something like this:

$sql="CREATE DATABASE `db1` AND/,/./etc `db2` AND/,/./etc `db3`";
$mysql_query=($sql,$con);
like image 871
Memphistoles Avatar asked Sep 07 '14 19:09

Memphistoles


2 Answers

Other options would be to create a SQL file such as:

/*myFile.sql*/ CREATE DATABASE db1; CREATE DATABASE db2;

Then run:

mysql -u user -p < myFile.sql

If you absolutely have to have it on a single console line you could do:

mysql -u user -p -e "CREATE DATABASE db3; CREATE DATABASE db4; ..."

like image 169
Twig Avatar answered Sep 20 '22 10:09

Twig


I am not sure, but it should work only separated by semicolon ; You could try

mysqli_multi_query

but you have to been connected to database with mysqli_connect not mysql_connect :(

like image 21
maskacovnik Avatar answered Sep 18 '22 10:09

maskacovnik