dear monks, i have to write a program, that takes database name, new user name and password as input from the user and create the database. I have written the following program.
use DBI; $drh = DBI->install_driver("mysql"); $database ='testg1'; $host ="localhost"; $user = "root"; $password = "passowrd"; $rc = $drh->func('createdb', $database, $host, $user, $password, ' +admin'); if ($rc == 1){print"new database created.."; } else{print "could not create database: $DBI::errstr\n";} ##################################### ######database created successfully ##################################### #################################### ### the following segment is giving problem ##################################### # the datasource $dbname = 'testg1'; my $db="$dbname:164.xxx.x.xxx:yyyy"; my $dbh = DBI->connect("DBI:mysql:$db",$user,$password) or die("ca +nt connect\n"); print "connected"; ########################################### ###### because of the error, i dont reach the following ##segment ############################################ $auser = 'newuser@localhost'; $pw = 'abcd'; my $query = qq|GRANT ALL on $db.* TO ? IDENTIFIED BY ?|; $dbh->do($query,undef,$auser,$pw) || die ("Could not do $query - E +rror: $DBI::errstr"); ###########################################
Though i am able to make the new database, i am not able to use it to create new user and grant rights. I am getting the following error.
DBI->connect(testg1:164.xxx.x.xxx:yyyy) failed: Access denied for user +: 'root@myhost' (Using password: YES) at create.pl line 19 cant connect
I can connect through the MySql console using same username and password. I can also create dtabase and grant rights etc from there. But through thr program, i am getting the "cant connect" error. Please help.

In reply to Create new user in MySQL by gmishra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.