MYSQL - 选择数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5287024/
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 19:05:28  来源:igfitidea点击:

MYSQL - select database

mysql

提问by Leahcim

I've managed to get into MySQL using the command line terminal, but when I tried to enter some SQL, it said 'no database selected'

我已经设法使用命令行终端进入 MySQL,但是当我尝试输入一些 SQL 时,它说“没有选择数据库”

how do I select a database? my database name is: photogallery

如何选择数据库?我的数据库名称是:相册

What code do I use to select it?

我用什么代码来选择它?

回答by Andrew Moore

Use USE. This will enable you to select the database.

使用USE. 这将使您能够选择数据库。

USE photogallery;

12.8.4: USE Syntax

12.8.4: USE 语法

You can also specify the database you want when connecting:

您还可以在连接时指定所需的数据库:

$ mysql -u user -p photogallery

回答by skaz

Switch to a database.

切换到数据库。

mysql> use [db name];

MySQL Commands

MySQL 命令

回答by Paul Truesdell

Hope this helps.

希望这可以帮助。

use [YOUR_DB_NAME];

回答by Nick T

Alternatively, you can give the "full location" to the database in your queries a la:

或者,您可以在查询中为数据库提供“完整位置”:

SELECT photo_id FROM [my database name].photogallery;

If using one more often than others, use USE. Even if you do, you can still use the database.tablesyntax.

如果使用一个比其他的更频繁,请使用USE。即使你这样做了,你仍然可以使用database.table语法。

回答by Lalit Dashora

Use the following steps to select the database:

使用以下步骤选择数据库:

mysql -u username -p

it will prompt for password, Please enter password. Now list all the databases

它会提示输入密码,请输入密码。现在列出所有数据库

show databases;

select the database which you want to select using the command:

使用以下命令选择要选择的数据库:

use databaseName;

select data from any table:

从任何表中选择数据:

select * from tableName limit 10;

You can select your database using the command use photogallery;Thanks !

您可以使用命令选择您的数据库use photogallery;谢谢!