18

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'
Dzinx
  • 55,586
  • 10
  • 60
  • 78
  • It works for me, no matter if I use ' or `. Difference between versions, maybe? (mine is 5.0 on Windows). – Dzinx Feb 03 '09 at 12:11
  • My hats off to the dba who manged this. As if writing good sql in itself was not challenging enough. Sigh! – Learning Feb 03 '09 at 12:57

7 Answers7

36

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`;
David Grant
  • 13,929
  • 3
  • 57
  • 63
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.

Mark
  • 16,772
  • 9
  • 42
  • 55
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.

comfroels
  • 109
  • 1
  • 8
2

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

USE "student registration";
Prakhar Londhe
  • 1,431
  • 1
  • 12
  • 26
  • 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? – Tomer Mar 25 '18 at 21:59
0

Use student registration without quotes.

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
Ahad Ahmed
  • 49
  • 1
  • 7
0

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

-1

You have to use square brackets to get this work:

Use [student registration]
zaengi
  • 39
  • 5