Creating o non-existing database

N

Nikos

This is soem per of my make.pl
Its supposed to create first time the database nikos_db or if its
already there to just delete it and recreate it.

$db = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
? DBI->connect('DBI:mysql:nikos_db', 'root', '')
: DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', '*****')
or print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0;

$db->do( "drop database if exists nikos_db" );
$db->do( "create database nikos_db" );
$db->do( "use nikos_db" );

If the database alrady exists no problem but if it want to be creates at
the time then the first db gives an error when i run make.pl and i must
then manually create it through mysql statemets in console.

What can i do so that Perl create the database nikos_db if it never benn
created?
 
P

peter pilsl

Nikos said:
If the database alrady exists no problem but if it want to be creates at
the time then the first db gives an error when i run make.pl and i must
then manually create it through mysql statemets in console.

Evidentely this is not a perl-problem. I dont know what it takes on your
sql-server to create a database. With postgreSQL there are mainly two
options:
i) call an extra programm coming with pgSQL
ii) connect to another database and create the needed database. Best the
postgres-system-datebase is used, cause it exists on most installations.

peter
 
X

xhoster

Nikos said:
This is soem per of my make.pl
Its supposed to create first time the database nikos_db or if its
already there to just delete it and recreate it.

$db = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
? DBI->connect('DBI:mysql:nikos_db', 'root', '')

? DBI->connect('DBI:mysql', 'root', '')
: DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', '*****')

: DBI->connect('DBI:mysql::50free.net', 'nikos_db', '*****')
or print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0;

$db->do( "drop database if exists nikos_db" );
$db->do( "create database nikos_db" );
$db->do( "use nikos_db" );

If the database alrady exists no problem but if it want to be creates at
the time then the first db gives an error when i run make.pl and i must
then manually create it through mysql statemets in console.

If you read the error it gives, then it should have been obvious what the
problem was. You can't connect to the server and specify a non-existant
database as your default. Connect the server without specifying any default
database, (re)create the database you want, then switch into it.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top