Re:Creating a database without connecting to MySQL with dbExpress?
Quote
"Mehmet Dogan" <mdo...@ekinoksyazilim.com> wrote in message
news:3e0da1be@newsgroups.borland.com...
Quote
> Hi;
> I tried to create a database with the code below;
> with SQLConnection1 do
> begin
> {1} Connected := False;
> {2} Params.Clear;
> {3} Params.Values['DriverName'] := 'MySQL';
> {4} Params.Values['HostName'] := 'localhost';
> {5} Params.Values['User_Name'] := 'root';
> {6} Params.Values['BlobSize'] := '-1';
> {7} Params.Values['Database'] := 'TestDB';
> {8} ExecuteDirect('CREATE DATABASE IF NOT EXISTS TestDB');
> {9} ExecuteDirect('CREATE TABLE IF NOT EXISTS TestDB.Table1 (field1
> tinyint(4) default NULL) TYPE=MyISAM');
> end;
> when the code run, it raises an exception "dbExpress Error: Invalid
> Username/Password." at line 8. But if I change the database name at line 7
> with " Params.Values['Database'] := 'MySQL'; " (or any existing database)
> then it works.
Yes, you must be "logged in" to an existing Database to create a database.
The default,
pre-existing database in MySQL is "MySQL" The default master-user is root
with no
password. You may "create" another master user, once you are "logged in":
GRANT ALL PRIVILEGES ON *.* TO sysdba@localhost IDENTIFIED BY
''masterkey'' WITH GRANT OPTION'
Quote
>But when I don't know anything about user's MySQL server's
> databases and user names, I always get exception. If some one can help, I
> will be very pleased.
> Best Regards...
> Mehmet DOGAN
This is a problem - you must optain a user/password combination if you are
using
a pre-installed MySQL database. This is called "security."
So you place your code in a try..except block, pop up a user/password
dialogue box.
Have the dbadmin person fill in the necessary info, hit okay, then create
your user/password
and use that from there on.
HTH,
John