MySQL database entry (database creation and table creation) -- Chen yuanbo and mysql Chen yuanbo
Create databases and tables1. database creation
(1) SQL statement Command database creation:
Create database Name (encoding garbled characters are not set for the database created by this method)
1 2 3 4 5 |
-- Set the database encoding method when creating a database -- Character set: Specifies the character set used by the database. UTF-8 cannot be written as UTF-8. -- COLLATE: Specifies the sorting rule of the database character set. The default sorting rule of utf8 is utf8_general_ci (viewed through show character set) Drop DatabaseIf EXISTS dbtest; Create DatabaseDbtestCHARACTER SETUtf8COLLATEUtf8_general_ci; |
Modify the database code:
Alter DatabaseDbtestCHARACTER SETUtf8COLLATEUtf8_general_ci;
The following uses the sqlyon GUI as an example to create a database:
(2)Graphical Database creation operation: Right-click Database on the left-side-Create Database
To avoid Chinese garbled characters in the database in the future, you need to set the database character set to utf8.
2. Create a table
(1)SQL statement command to create a table:
Create table Name (
Column name data type (length ),
Column name data type (length)
);
For example:
Create table test (
Id INT,
Username VARCHAR (20 ),
Age INT (4)
)
Note: The int type does not need to be written. The default value is 11 characters. The length of the string must be specified and separated by commas.
(2)Create a graph table:
Right-click Database ----- create --- table
The above is a preliminary explanation of the MySQL database creation and table creation methods. If there are any unreasonable reasons, please forgive me and correct me.