Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select a MySQL database through CLI?

Tags:

mysql

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'

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

What code do I use to select it?

like image 613
Leahcim Avatar asked Mar 13 '11 02:03

Leahcim


People also ask

Which MySQL command is used to select database?

You can use SQL command USE to select a particular database.

How do I open an existing MySQL database from the command line?

To access a specific database, type the following command at the mysql> prompt, replacing dbname with the name of the database that you want to access: Copy use dbname; Make sure you do not forget the semicolon at the end of the statement. After you access a database, you can run SQL queries, list tables, and so on.

How do I switch between MySQL databases?

Change or switch DATABASE in MySQL To change or switch DATABASE, run the same USE database_name query with the new database name that you wish to work on. In the example shown above, USE db3; changes the database, from db2 to db3, on which your SQL queries effect on.


1 Answers

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 
like image 85
Andrew Moore Avatar answered Oct 07 '22 21:10

Andrew Moore