How can I create the database through query if the database name has blank spaces in it

Hi All,

I am new to MySQL. I am using SQLYOG for database manipulations. I have a doubt regarding creation of database. When I tried to create a database “a b c” through the following query " create database ‘a b c’ " , I got an error message. But by clicking on the ‘DB’ menu in the menubar and selecting ‘create database’ menuitem, I am able to create the database ‘a b c’.

Kindly let me know How can I create the database through query if the database name has blank spaces in it?

Regards,
A.S.Kalyan.

o:my> set sql_quote_show_create=1;
Query OK, 0 rows affected (0.00 sec)

o:my> create database a b c;
Query OK, 1 row affected (0.00 sec)

o:my> show databases like ‘a%’;
±--------------+
| Database (a%) |
±--------------+
| a b c |
±--------------+
1 row in set (0.01 sec)

o:my> drop database a b c;
Query OK, 0 rows affected (0.00 sec)

Although it is possible to use backticks in MySQL to create all kinds of strange database/table/column names.

I strongly recommend against it. It’s just asking for trouble.
For example, are you happier with a database name with spaces in it? You have already realized that there are problems with it.
If you want to separate a name consisting of several words use underscore or an uppercase letter instead (note however that mysql on windows is not case sensitive on database/table names since windows hasn’t a case sensitive filesystem.

Hi Mike…

Glad to have some useful help here by you. I tried to follow your instructions. Though the statement “set sql_quote_show_create=1;” has worked fine but the statement for creating the database didn’t. It has shown 1064 error, asking to check the manual. Can u pls send some other way to handle the problem?
I am facing some other problem too. As I have created some other databases from the GUI I developed in Java, they are not being updated concurrently. If u have an idea abt java, here is the code that I used to create the statement.

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSe t.CONCUR_UPDATABLE);

‘con’ is the connection to the mysql database here. If u can help me in some way, I’ld be thankful.

Regards,

Hi sterin,

Thank u for that suggestion but we have a task to create such databases too.

Regards,

Hi,

Not enough info to go on - get rid of the semicolon?

p.s.

I agree that spaces, caps, etc… are a really bad
idea for names of tables/columns, etc… you will pay
for it somewhere down the road.