加入收藏 | 设为首页 | 会员中心 | 我要投稿 财气旺网 - 财气网 (https://www.caiqiwang.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

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

发布时间:2022-10-18 22:00:59 所属栏目: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 th

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数据库MySQL 选择数据库,所有后续操作将在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.

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



   
      Selecting MySQL Database
   
   
   
      <?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);
      ?>
   


翻译自:

mysql 选择数据库

(编辑:财气旺网 - 财气网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!