MySQL Create database
The CREATE DATABASE syntax is used to create a database.
CREATE DATABASE db_name
Creating a database requires corresponding user rights, such as the root user
Select the database
To perform operations on a database or table, you need to select a database.
Create a table
CREATE TABLE table_name ( Column1 data_type, Column2 data_type, Column3 data_type )
In the above syntax, column(1,2,3) is the field name, followed by the data type.
CREATE TABLE user id mediumint(8), username varchar(20), password char(32), email varchar(40) );
In general, the creation of data tables have the following precautions
- The original record data and the corresponding relationship between the table
- Table names and field names should follow the naming syntax and should be explicitly defined
- Specifies the data type of the field
- Specifies whether the field's other attributes are non-null, whether there are default values, and so on
- Definition of the properties of the table such as the main foreign keys, constraints, indexes and so on
- Relationship with other tables