How should I choose a database

Select MySQL database

After you connect to the MySQL database, there may have multiple databases that can be tampered with, so you have the database that you want to work with.


Select the MySQL database from the command prompt window

In the mysql> prompt window it can be very easy to choose a specific database. You can choose to specify the database using SQL commands.

Examples

The following examples database w3big selected:

[[email protected]] # mysql -u root -p Enter password: ****** mysql> use w3big; Database changed mysql>

After the above command is run, if you have successfully selected w3big database, the database will be run in subsequent operations in w3big.

Note: All database names, table names and table fields are case-sensitive. So if you need to use SQL commands, enter the correct name.


Select the MySQL database PHP script

PHP provides functions mysql_select_db to select a database. After the successful implementation of the function, it will return TRUE, otherwise it will return FALSE.

grammar

bool mysql_select_db (db_name, connection);
parameter description
db_name Required. How to choose the specified database.
connection Optional. Defaults MySQL connection. Unless otherwise stated, the last connection.

Examples

The following example shows how to use mysql_select_db function to select a database:

<html> <head> <meta charset="utf-8"> <title>选择 MySQL 数据库</title> </head> <body> <?php $dbhost = 'localhost:3036'; $dbuser = 'guest'; $dbpass = 'guest123'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('连接失败: ' . mysql_error()); } echo '连接成功'; mysql_select_db( 'w3big' ); mysql_close($conn); ?> </body> </html>