John
John

Reputation:

Selecting a database in mysql with spaces in its name

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'

Upvotes: 19

Views: 51303

Answers (7)

Nirmal_codes
Nirmal_codes

Reputation: 1

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

Upvotes: 0

Ahad Ahmed
Ahad Ahmed

Reputation: 49

Use student registration without quotes.

Upvotes: 0

Prakhar Londhe
Prakhar Londhe

Reputation: 1471

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

USE "student registration";

Upvotes: 2

comfroels
comfroels

Reputation: 109

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

use `student registration`;

At least that would be yours.

Upvotes: 2

zaengi
zaengi

Reputation: 39

You have to use square brackets to get this work:

Use [student registration]

Upvotes: -1

Mark
Mark

Reputation: 17142

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.

Upvotes: 13

David Grant
David Grant

Reputation: 14225

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`;

Upvotes: 39

Related Questions