Selecting a database in mysql with spaces in its name
Asked Answered
A

7

19

I want to select my particular database in mysql console, but the problem is that my database name has a space in between and mysql ignores the part after the space. For instance, when i give the command:

use 'student registration'

I get the message:

cannot find database 'student'
Anent answered 3/2, 2009 at 11:57 Comment(2)
It works for me, no matter if I use ' or `. Difference between versions, maybe? (mine is 5.0 on Windows).Sorkin
My hats off to the dba who manged this. As if writing good sql in itself was not challenging enough. Sigh!Latour
R
38

You should try using back ticks ("`") to quote your database name. Generally speaking, it's probably better to use a naming convention to eliminate white space, e.g.

USE `StudentRegistration`;

or

USE `student_registration`;
Ritaritardando answered 3/2, 2009 at 11:59 Comment(1)
Even with spaces, it's better to use these back ticks. Nice answer David. +1Durno
S
13

You have two options.

1 Enclose the database name in backticks or single quotes.

USE `student registration`;
USE 'student registration';

2 Escape the white space character.

USE student\ registration;

Oddly enough this produces.

ERROR: Unknown command '\ '.

But still changes the database.

Stoush answered 3/2, 2009 at 12:53 Comment(0)
S
2

When I had to deal with other people's tables with spaces the following worked:

use `student registration`;

At least that would be yours.

Sextet answered 9/4, 2014 at 18:24 Comment(0)
F
2

Use Double quotes instead of single, double quotes worked for me :

USE "student registration";
Fabiola answered 24/1, 2016 at 12:33 Comment(1)
Hi I used all techniques here such as "order details" [order details] and 'order details' but they all didnlt work do you have a clue?Hurricane
U
0

Use student registration without quotes.

Ulund answered 8/1, 2018 at 10:50 Comment(0)
F
0

USE student registration; - This worked for me like a gem... Also tried other alternatives provided here... But nothing worked for me in MySQL;

Faxun answered 8/8, 2023 at 12:38 Comment(0)
O
-1

You have to use square brackets to get this work:

Use [student registration]
Oney answered 27/8, 2013 at 13:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.