Selecting MySQL Database from the Command Prompt

0
191

There be a situation when there are different databases present and you have to select one of them to work on. So after MySql connection you can do the following things:

Selecting MySQL Database from Command Prompt:

This is very simple to select a particular database from mysql> prompt. You can use SQL command use to select a particular database.

[bha size=’468×60′ variation=’01’ align=’none’]

Example:

Here is an example to select database called  “DATABASE TUTORIALS”:

[[email protected]]# mysql -u root -p

Enter password:******

mysql> use DATABASE TUTORIALS;

Database changed

mysql>

As you select “DATABASE TUTORIALS” database and all the subsequent operations will be performed on DATABASE TUTORIALS.

 

Selecting MySQL Database Using PHP Script:

PHP provides function mysql_select_db to select a database. It returns TRUE on success or FALSE on failure.

Syntax:

bool mysql_select_db( db_name, connection );

 

Command Detail
db_name MySQL Database name is to be selected by the user
connection Optional – then last opened connection by mysql_connect will be used.

Example:

How to select a database.

 
[php]






[/php]
Facebook Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.