MySQL database operation commands and mysql commands
Note: MySQL databases are case-insensitive.
1. Create a database:Create database Thinkgamer;
2. delete a database:Drop database Thinkgamer;
3. Select a database:Use Thinkgamer;
4. Create a data table:
Mysql> create table cyan
-> (
-> Student ID int (3) not null primary key,
-> Name char (3 );
-> Gender char (1) not null default 1
->) Engine = innodb;
Press enter. not null indicates that this field cannot be blank. primary key indicates that the primary key is set and default name is 1 by default.
5. delete a table:Drop table cyan;
6. add columns to the table:Alter table cyan add char (20 );
7. display information about the table:Describe cyan;
8. display the information of a column:Select student ID from cyan;
9. add information to the table:Insert cyan values ("111", "Thinkgamer", "female", "dance ");
10. Modify the information of a table row:
Mysql> update cyan
-> Set gender = "male", hobbies = "badminton"
-> Where student no. = 111;
Press enter.
1. Modify the information of multiple tables:
Mysql> update table_name1, table_name2
-> Set table_name1. Gender = "male", table_name2. Gender = "female"
-> Where table_name1.id = table_name2.id;
Press enter.
12. delete a row:Delete from cyan where student ID = 111;
13. remove a person with a gender:Delete from cyan where gender = female;
14. Delete multiple rows from multiple tables:
Mysql> delete table1, table2
-> From table1, table2, table3
-> Where table1.id = table2.id and table2.id = table3.id;
Press enter.
15. Clear table data:Truncate table cyan;
Note: once the data is cleared, it cannot be recovered.
Others:
Select user (); displays the current user.
Select @ version; displays the database version.
Show cyan status; displays the status of the currently used table
Show character set; displays the character sets supported by the database
Show variables like '% char %' view default Character Set
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.