Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: DBD::mysql::db do failed: You have an error in your SQL syntax;

by KurtSchwind (Chaplain)
on Jan 05, 2015 at 12:36 UTC ( [id://1112183]=note: print w/replies, xml ) Need Help??


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

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.1.56 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights res +erved. This software comes with ABSOLUTELY NO WARRANTY. This is free software +, and you are welcome to modify and redistribute it under the GPL v2 lic +ense Type 'help;' or '\h' for help. Type '\c' to clear the current input st +atement. mysql> create database test-dash; ERROR 1064 (42000): You have an error in your SQL syntax; check the ma +nual that corresponds to your MySQL server version for the right synt +ax to use near '-dash' at line 1 mysql>

You cannot put dashes in database names.

mysql> create database 'test-dash'; ERROR 1064 (42000): You have an error in your SQL syntax; check the ma +nual that corresponds to your MySQL server version for the right synt +ax to use near ''test-dash'' at line 1 mysql> create database "test-dash"; ERROR 1064 (42000): You have an error in your SQL syntax; check the ma +nual that corresponds to your MySQL server version for the right synt +ax to use near '"test-dash"' at line 1 mysql> create database test\-dash; ERROR: Unknown command '\-'. ERROR 1064 (42000): You have an error in your SQL syntax; check the ma +nual that corresponds to your MySQL server version for the right synt +ax to use near '\-dash' at line 1
--
I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.

Replies are listed 'Best First'.
Re^2: DBD::mysql::db do failed: You have an error in your SQL syntax;
by rnewsham (Curate) on Jan 05, 2015 at 12:45 UTC

    You can have a dash in a database name if it is done inside backticks

    mysql> create database `test-dash`; Query OK, 1 row affected (0.05 sec)
      Thanks rnewsham. It worked like a champ Modified code
      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; } }

      Forgot about back-tick quoting in MYSQL. Yep. That'll work.

      --
      I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1112183]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-24 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found