MySQL 在mysql中选择名称中带有空格的数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/506826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:44:21  来源:igfitidea点击:

Selecting a database in mysql with spaces in its name

mysqldatabaseconsolespaces

提问by David Grant

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:

我想在 mysql 控制台中选择我的特定数据库,但问题是我的数据库名称之间有一个空格,而 mysql 忽略了空格后面的部分。例如,当我发出命令时:

use 'student registration'

I get the message:

我收到消息:

cannot find database 'student'

回答by David Grant

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

回答by Mark

You have two options.

你有两个选择。

1 Enclose the database name in backticks or single quotes.

1 用反引号或单引号将数据库名称引起来。

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

2 Escape the white space character.

2 转义空白字符。

USE student\ registration;

USE student\ registration;

Oddly enough this produces.

奇怪的是,这会产生。

ERROR: Unknown command '\ '.

错误:未知命令“\”。

But still changes the database.

但仍然更改数据库。

回答by comfroels

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

当我不得不用空格处理其他人的桌子时,以下工作:

use `student registration`;

At least that would be yours.

至少那将是你的。

回答by Prakhar Londhe

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

使用双引号而不是单引号,双引号对我有用:

USE "student registration";

回答by Ahad Ahmed

Use student registrationwithout quotes.

student registration不带引号使用。

回答by zaengi

You have to use square brackets to get this work:

你必须使用方括号来完成这项工作:

Use [student registration]