Operation of MySQL Database
One: View all the databases in MySQL
SHOW DATABASES;
Two: Create a database
Cretae database name;
Three: Deleting a database
DROP database name;
Four: View the storage engines supported by the database
SHOW ENGINES;
Four: Connect MySQL database
Use database name;
Operation of tables in MySQL database
One: View all tables in the database
SHOW TABLES;
Second: View the structure of the table
DESC table name; (basic structure);
Or
SHOW CREATE table table name; (detailed structure);
Three: Create a table
CREATE Table table name (field name data type constraint, field name data type constraint,....);
| Constraint conditions |
Description |
| PRIMARY KEY |
Indicates that the field is the primary key of the table and can uniquely identify the corresponding element |
| FOREIGN KEY |
Indicates that the field is a foreign key to the table and is the primary key of the table to which it is contacted |
| Not NULL |
Indicates that the field cannot be empty |
| UNIQUE |
Indicates that the value of the field is unique and does not duplicate |
| Auto_increment |
Indicates that the value of the field is automatically incremented |
| DEFAULT |
is the default value for the field |
Four: Modify table name
ALTER tbale Old table name RENAME new table name;
V: Delete Table
DROP table name;
Six: Modifying field data types
ALTER table name MODIFY field name new data type;
Seven: Modify field sorting
ALTER table name MODIFY field name first/after field name;
Eight : Modify field Name
ALTER Table name change old field name new data type of new field name;
Nine : Add field (before/Insert "field name" before after/Insert "field name")
ALTER Table name ADD new field name new data type constraint [before/after field name];
Ten: Delete a field
ALTER table name DROP field name;
11: Change the storage engine for a table
ALTER table name engine= storage engine name;
| Storage Engine |
Description |
| Inoodb |
Supports the logic of things, has event rollback, concurrency, and supports foreign keys. |
| MyISAM |
Small footprint, fast processing speed. |
| MEMORY |
Data tables stored in memory, fast, the disadvantage is that the data is easy to lose, short life cycle. |
MySQL database learning----MySQL database, table operations, and engine differences