MYSQL - select a database

I managed to log into MySQL using the command line terminal, but when I tried to enter some SQL, he said: "no database selected"

How to choose a database? my database: photo gallery

What code can I use to select it?

+43
mysql
Mar 13 2018-11-11T00:
source share
6 answers

Use USE . This will allow you to select a database.

 USE photogallery; 

12.8.4: USE Syntax

You can also specify the desired database when connecting:

 $ mysql -u user -p password photogallery 
+84
Mar 13 2018-11-11T00:
source share

Switch to the database.

 mysql> use [db name];

MySQL Commands

+15
Mar 13 2018-11-11T00:
source share

Hope this helps.

use [database name];

+10
Mar 13 2018-11-11T00:
source share

Alternatively, you can specify the "full location" of the database in your a la queries:

 SELECT photo_id FROM [my database name].photogallery; 

If you are using one more than the others, use USE . Even if you do, you can still use the database.table syntax.

+9
Jul 09 '13 at 17:08
source share

Follow these steps to select a database:

 mysql -u username -p 

a password request appears, enter the password. Now we list all the databases

 show databases; 

select the database 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 use photogallery; command use photogallery; Thank!

+2
Jul 13 '17 at 5:42 on
source share

Choose all:

 select * from Table_name; 

To select a specific column name:

 select column_name from Table_name; 
-one
Jul 18 '17 at 17:38 on
source share



All Articles