views:

967

answers:

3

Hi All

I want to create a database which name will have special characters in it. for example, (., - , _, @, #, $, %, &, *)

can anyone provide any output on this?

+5  A: 

I would strongly recommend that you do not create databases with such names. But if you absolutely must, here are the restrictions:

  • No identifier can contain ASCII NUL (0x00) or a byte with a value of 255.
  • Database, table, and column names should not end with space characters.
  • Database and table names cannot contain “/”, “\”, “.”, or characters that are not allowed in file names.

To create a database, you can do the following:

mysql> create database `really@strange*database$name`;
Andre Miller
Great answer +1
ichiban
i want to create it dynamically, can i do that? for example - i want to give a database name to a variable set @a = name.surname;create database @a;
MySQL DBA
Thanks a lot Andre. It was a great help as i was needing to it, though it is not advisable. Thanks :)
MySQL DBA
+2  A: 

Simple: Don't.

You can escape exotic table names using the backtick in mysql, but I don't know if you can use anything inside the backticks. It will give great amounts of pain during the rest of your software life cycle.

I would rather recommend creating another table to hold that exotic names.

-- Example:
CREATE TABLE _DatabaseMetadata (
    databaseName VARCHAR(255),
    exoticName VARCHAR(255)
) DEFAULT CHARSET=utf8;
soulmerge
+1  A: 

Hi!

I got it I used the prepare statement for this. :)

MySQL DBA