I. Basic Database Operations
1. Create a database
Create database is used to create a database. The basic syntax is as follows:
CREATE DATABASE database_name
The following is an example:
We want to create a database named "test_db.
We use the following create database statement:
CREATE DATABASE test_django
You can use create table to add database tables.
2. view the database
After the creation, we can use the following syntax to view the databases in MySQL (note that there is a last S)
SHOW DATABASES
In this way, we can see all the databases in MySQL:
At this time, we can see that in addition to the test_django database we created, there are three databases that come with MySQL:
The first database information_schema: provides a way to access database metadata.
MySQL is the core database of MySQL. It is mainly responsible for storing the control and management information required by MySQL, such as database users, permission settings, and keywords. It cannot be deleted. If you are not familiar with MySQL, we recommend that you do not modify the table information in the database.
The third database is test: A test database created during installation. It is named like a completely empty database and can be deleted without any tables.
3. delete a database
The syntax for deleting a database is similar to that for creating a database. The drop syntax is used:
DROP DATABASE test
After deletion, we can use show databases to view all the databases. We can see that the test database has been deleted.