On 5/17/06, Philippe Martin <[EMAIL PROTECTED]> wrote:
John Salerno wrote:

> Since the connect method of mysqldb requires a database name, it seems
> like you can't use it without having a database already created. So is
> there a way to connect to your mysql server (without a specified
> database) in order to create a new database (i.e., the CREATE DATABASE
> query)?
>
> Thanks.

I'm no expert but: can't you spawn mysql with a script/scheme ?

Philippe

MySQLdb.connect does not require a database name. ie.:

>>> import MySqlDB
>>> db = MySQLdb.connect(host='localhost', user='root', passwd='xxxx')
>>> csr = db.cursor ()
>>> csr.execute('''show databases''')
6L
>>> for d in csr.fetchall():
    print d

('cc',)
('cc_41',)
('mysql',)
('purchaseorder',)
('test',)
('xsldb',)
>>> csr.execute('''create database newdb''')
1L
>>> csr.execute('''show databases''')
7L
>>> for d in csr.fetchall():
    print d

('cc',)
('cc_41',)
('mysql',)
('newdb',)
('purchaseorder',)
('test',)
('xsldb',)
>>>

Later,
Lou
--
Artificial Intelligence is no match for Natural Stupidity
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to