Creating a non-existing database through Perl

B

beatnik

Yes but actually "nikos_db" would be the first database in existance.
There is no other database created before it. My aproiach so far was to
create that database "nikos_db" from console *manually* othewise i was
getting an error. On the other hand if the database existed then it
could conenct to it first and then delete it? But what about the first
time that need to be created?
 
B

beatnik

Gunnar said:
[ Provide some context when replying to a message, and don't
unnecessarily start a new thread.

Study the posting guidelines for this group before posting again.
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html ]
Yes but actually "nikos_db" would be the first database in existance.

Sorry, here is the relevant code i was talking about:

<code>
This is some 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" );
</code>
 
G

Gunnar Hjalmarsson

I

ioneabu

beatnik said:
Gunnar said:
[ Provide some context when replying to a message, and don't
unnecessarily start a new thread.

Study the posting guidelines for this group before posting again.
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html ]
Yes but actually "nikos_db" would be the first database in
existance.

Sorry, here is the relevant code i was talking about:

<code>
This is some 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" );
</code>

Is the problem that DBI requires you to specify an existing database to
connect? Just use one that is always there, like 'test' or 'mysql' and
then you can create your new one.

wana
 
B

beatnik

Is the problem that DBI requires you to specify an existing database to
connect? Just use one that is always there, like 'test' or 'mysql' and
then you can create your new one.

Well i dont know what DBI requires, but what if there isnt such
databases as test or mysql?

Lets assume that there is no other database available. Then what?

Iam tellign this because my webpage script runs in 2 different machines.
One has 'test' and 'mysql' other doesnt.
So the aproach of connecting to a diff database wont work but even if it
did its other database dependant.
 
I

ioneabu

beatnik said:
Well i dont know what DBI requires, but what if there isnt such
databases as test or mysql?

Lets assume that there is no other database available. Then what?

Iam tellign this because my webpage script runs in 2 different machines.
One has 'test' and 'mysql' other doesnt.
So the aproach of connecting to a diff database wont work but even if it
did its other database dependant.

from perldoc DBD::mysql

connect
use DBI;

$dsn = "DBI:mysql:$database";
$dsn = "DBI:mysql:database=$database;host=$hostname";
$dsn =
"DBI:mysql:database=$database;host=$hostname;port=$port";

$dbh = DBI->connect($dsn, $user, $password);

A "database" must always be specified.

It looks like you are stuck having to specify a database to get in. I
am no expert on mysql, but isn't it true that when the grant tables are
set up, there must be a database named 'mysql' present? The one that
does not have it is not set up securely for production use anyway. You
should be able to rely on properly setup mysql installations to have
the 'mysql' database present.

I think that the mysql_install_db script sets it up.

Good luck!

wana
 
X

xhoster

beatnik said:
Well i dont know what DBI requires, but what if there isnt such
databases as test or mysql?

Then log on without specifying a database, as I showed in a previous
post.
Lets assume that there is no other database available. Then what?

If I recall correctly, if you don't have a mysql database, then you don't
have a functioning mysql server. Clearly you can't connect to a mysql
server that doesn't exist.

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top