Hi Monks,

I am running a database utility and I am creating a database through a menu driven script. I am getting the following error

DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-secure-test' at line 1 at C:/Users/Sennovate/workspace/Perl/Automation/Sennovate/MySQL DB Creation/ssg-db-utility.pl line 79, <STDIN> line 5.

I am using Strawberry Perl 5.20.1

Here is my code snippet

sub create_database { print "Please enter the hostname:"; chomp($hostname = <STDIN>); print "Please enter the name of the new MySQL database:"; chomp($database = <STDIN>); $dsn = "dbi:$driver::$hostname:$port"; print "Please type the MySQL root username:"; chomp($username = <STDIN>); print "Please type the MySQL root password:"; chomp($password = <STDIN>); $dbh = DBI->connect($dsn, $username, $password); $result = $dbh->do("create database $database"); $dbh->do("use $database"); if($result) { say "Database '$database' created successfully"; } else { say "Database '$database' creation failed"; exit; } }

Here is the input

---------------------------------------- S E N N O V A T E I N C SSG Database Utility - Version 1.1 Copyright Sennovate Inc, 2014 ---------------------------------------- M E N U ------- 1. Create new database 2. Connect to existing database 3. Create tables 4. Create user 5. Drop existing database 6. Quit Please enter your choice:1 Please enter the hostname:db0002.stage-us.sennovate.com Please enter the name of the new MySQL database:ssg-secure-test Please type the MySQL root username:ssg-stage Please type the MySQL root password:p7ZUrf59zJHYMMuLKfWTxC DBD::mysql::db do failed: You have an error in your SQL syntax; check +the manual that corresponds to your MySQL server version for the righ +t syntax to use near '-secure-test' at line 1 at C:/Users/Sennovate/w +orkspace/Perl/Automation/Sennovate/MySQL DB Creation/ssg-db-utility.p +l line 79, <STDIN> line 5. Database 'ssg-secure-test' creation failed DBD::mysql::db do failed: You have an error in your SQL syntax; check +the manual that corresponds to your MySQL server version for the righ +t syntax to use near '-secure-test' at line 1 at C:/Users/Sennovate/w +orkspace/Perl/Automation/Sennovate/MySQL DB Creation/ssg-db-utility.p +l line 80, <STDIN> line 5.

Please help


In reply to DBD::mysql::db do failed: You have an error in your SQL syntax; by shajiindia

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.