MySQL creates a database
MySQL to create a database using mysqladmin to create a database
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.
Example
The following command simply demonstrates the process of creating a database, named RUNOOB:
[root@host] # mysqladmin-u root-p create RUNOOBEnter password:*
The MySQL database RUNOOB is created after the above command is executed successfully.
Create a database using a PHP script
PHP uses the mysqli_query function to create or delete an MySQL database.
This function takes two arguments and returns TRUE on successful execution, or FALSE otherwise.
Syntax mysqli_query (connection,query,resultmode); parameter description connection is required. Specifies the MySQL connection to be used. Query is required, specifying the query string. Resultmode
Optional. A constant. It can be any of the following values:
MYSQLI_USE_RESULT (use this if you need to retrieve a large amount of data)
MYSQLI_STORE_RESULT (default)
Example
The following example demonstrates using PHP to create a database:
Create a database
When the execution is successful, the following result is returned:
If the database already exists, the following result is returned after execution:
MySQL connection
MySQL deletes the database
Note list
Windhut
Abc***@163.com
After logging in using root, you can use the
CREATE DATABASE IF NOT EXISTS RUNOOB DEFAULT CHARSET utf8 COLLATE utf8_general_ci
To create a database, what this command does:
1. If the database does not exist, it is created, and if it does, it is not created.
two。 Create a RUNOOB database and set the code set to utf8