After logging in to the MySQL service, we can use the create command to create a database. The syntax is as follows:
CREATE DATABASE database name;
The following command simply demonstrates the process of creating a database, the data name is RUNOOB:
[[emailprotected]]# mysql -u root -p Enter< span class="pln"> password:****** # After logging in, enter the terminal mysql> create DATABASE RUNOOB; span>
Use mysqladmin to create a database
As a normal user, you may need specific permissions to create or delete a MySQL database.
So we use the root user to log in here. The root user has the highest authority. You can use the mysql mysqladmin command to create a database.
The following command simply demonstrates the process of creating a database, the data name is RUNOOB:
[< span class="pln">[email protected]]# mysqladmin -u root < span class="pun">-p create RUNOOB Enter password:**** **
After the above command is executed successfully, the MySQL database RUNOOB will be created.
Use a PHP script to create a database
PHP uses the mysqli_query function to create or delete a MySQL database.
This function has two parameters, it returns TRUE when the execution is successful, otherwise it returns FALSE.
Syntax
mysqli_query(connection,query,resultmode); span>
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to be used. |
query | Required, specifies the query string. |
resultmode |
Optional. A constant. Can be any of the following values:
|
Example
The following example demonstrates the use of PHP to create a database:
Create a database
After the execution is successful, the following result will be returned:
If the database already exists, after execution, the following result will be returned:
Create a database
< /span>