开发者

How do I select a MySQL database through CLI?

I've managed to get into MySQL using the command line terminal, but when I tried to enter some SQL, it said 'no database select开发者_如何学Pythoned'

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

What code do I use to select it?


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

USE photogallery;

12.8.4: USE Syntax

You can also specify the database you want when connecting:

$ mysql -u user -p photogallery


While invoking the mysql CLI, you can specify the database name through the -D option. From mysql --help:

-D, --database=name Database to use.

I use this command:

mysql -h <db_host> -u <user> -D <db_name> -p


Switch to a database.

mysql> use [db name];

MySQL Commands


Hope this helps.

use [YOUR_DB_NAME];


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.table syntax.


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

eg. if your database's name is gregs_list, then it will be like this >>

USE gregs_list;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜