Problems with hyphens in MySQL.

MySQL does not handle hyphens very well. For example, I created a database called "modx-test" and then tried to delete it, which failed due to a syntax error:

mysql> drop database modx-test;
ERROR 1064 (42000): 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 '-test' at line 1

To get around this problem, change the SQL mode to ANSI so that you can surround the database name with double quotes:

mysql> set sql_mode=ANSI;
Query OK, 0 rows affected (0.00 sec)
mysql> drop database "modx-test";
Query OK, 39 rows affected (0.52 sec)

References

Last modified: 10/06/2008 Tags: (none)

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top