4.2.6. MySQL creates a database

发布时间 : 2025-10-25 13:32:51 UTC      

Page Views: 10 views

After logging into the MySQL service, we can use the create Command to create the database, the syntax is as follows:

CREATE DATABASE 数据库名; 

The following command simply demonstrates the process of creating a database, named RUNOOB:

[root@host]# mysql -u root -p Enter password:****** # 登录后进入终端 mysql> create DATABASE RUNOOB; 

Create a database using mysqladmin

With normal users, you may need specific permissions to create or delete MySQL databases.

So we use the root user to log in, and the root user has the highest privileges, so we can use the mysql mysqladmin command to create the database.

The following command simply demonstrates the process of creating a database, named RUNOOB:

[root@host]# mysqladmin -u root -p create RUNOOB Enter password:****** 

The MySQL database RUNOOB is created after the above command is executed successfully.

Create a database using a PHP script

PHP usage mysqli_query Function to create or delete an MySQL database.

This function takes two arguments and returns on successful execution. TRUE Otherwise, return FALSE .

Grammar

mysqli_query(connection,query,resultmode); 

Parameters.

Description

connection

Necessary. Specifies the MySQL connection to be used.

query

Required, specify the query string.

resultmode

Optional. A constant. It can be any of the following values:

  • MYSQLI_USE_RESULT(如果需要检索大量数据,请使用这个)

  • MYSQLI_STORE_RESULT(默认)

Example

The following example demonstrates using PHP to create a database:

Create a database

';$sql='CREATE DATABASE RUNOOB';$retval=mysqli_query($conn,$sql);if(!$retval){die('创建数据库失败:'.mysqli_error($conn));}echo"数据库 RUNOOB 创建成功\\n";mysqli_close($conn);?> 

When the execution is successful, the following result is returned:

Image0

If the database already exists, the following result is returned after execution:

Image1

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。