mysql 选择数据库_选择MySQL数据库

本文介绍了如何在连接到MySQL服务器后选择数据库。从命令提示符下,你可以使用`use`命令选择数据库,例如`use TUTORIALS;`。而在PHP中,可以使用`mysql_select_db`函数来选择数据库,如`mysql_select_db('TUTORIALS')`。注意,数据库名在MySQL中是区分大小写的。
摘要由CSDN通过智能技术生成
mysql 选择数据库

mysql 选择数据库

选择MySQL数据库 (Selecting MySQL Database)

Once you get connected with the MySQL server, it is required to select a database to work with. This is because there might be more than one database available with the MySQL Server.

与MySQL服务器建立连接后,需要选择要使用的数据库。 这是因为MySQL服务器可能有多个数据库可用。

从命令提示符中选择MySQL数据库 (Selecting MySQL Database from the Command Prompt)

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

从mysql>提示符下选择数据库非常简单。 您可以使用SQL命令use选择数据库。

(Example)

Here is an example to select a database called TUTORIALS

这是一个选择名为TUTORIALS的数据库的示例-


[root@host]# mysql -u root -p
Enter password:******
mysql> use TUTORIALS;
Database changed
mysql> 

Now, you have selected the TUTORIALS database and all the subsequent operations will be performed on the TUTORIALS database.

现在,您已经选择了TUTORIALS数据库,所有后续操作将在TUTORIALS数据库上执行。

NOTE − All the database names, table names, table fields name are case sensitive. So you would have to use the proper names while giving any SQL command.

–所有数据库名称,表名称,表字段名称均区分大小写。 因此,在发出任何SQL命令时,您必须使用适当的名称。

使用PHP脚本选择MySQL数据库 (Selecting a MySQL Database Using PHP Script)

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

PHP提供了mysql_select_db函数来选择数据库。 成功返回TRUE,失败返回FALSE。

句法 (Syntax)


bool mysql_select_db( db_name, connection );

Sr.No.Parameter & Description
1

db_name

Required − MySQL Database name to be selected

2

connection

Optional − if not specified, then the last opened connection by mysql_connect will be used.

序号 参数及说明
1个

db_name

必需-要选择MySQL数据库名称

2

连接

可选-如果未指定,则将使用mysql_connect上次打开的连接。

(Example)

Here is an example showing you how to select a database.

这是显示如何选择数据库的示例。


<html>
   <head>
      <title>Selecting MySQL Database</title>
   </head>
   
   <body>
      <?php
         $dbhost = 'localhost:3036';
         $dbuser = 'guest';
         $dbpass = 'guest123';
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         
         if(! $conn ) {
            die('Could not connect: ' . mysql_error());
         }
         echo 'Connected successfully';
         mysql_select_db( 'TUTORIALS' );
         
         mysql_close($conn);
      ?>
   </body>
</html>

翻译自: https://www.tutorialspoint.com/mysql/mysql-select-database.htm

mysql 选择数据库

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值