I haven't done any database-related things for a long time, and I can't remember the commonly used SQL statements! Today, I am reading mysql-related things in the country chart all day. Now let's make a simple arrangement. (Operating System: UBUNTU)
1. Start MySQL on the terminal:/etc/init. d/MySQL start;
2. log on to MySQL: mysql-uroot-P (Log On with the root account) and enter the password;
3. View All Database names: Show databases;
4. Select a database operation: Use database_name;
5. view all the table names in the current database: show tables;
6. Create a database: Create Database database_name;
7. delete a database: drop database database_name;
8. Create a table: Create Table mytest (UID bigint (20) not null, uname varchar (20) not null );
9. delete a table: Drop table mytest;
10. SQL insert statement: insert into table_name (col1, col2) values (value1, value2 );
11. SQL update statement: Update table_name set col1 = 'value1', col2 = 'value2' where where_definition;
12. SQL query statement: Select * From table_name where ...... (the most complex Statement)
13. SQL deletion statement: delete from table_name where...
14. Add the table structure field: Alert table table_name add column field1 date, add column field2 time...
15. Delete the table structure field: Alert table table_name drop field1;
16. view the table structure: Show columns from table_name;
17. Use of Limit: Select * From table_name limit 3; // only three lines are displayed on each page.
Select * From table_name limit 3, 4 // four results are displayed starting from the third query result.
This can be used for paging.
18. Sort the query results: Select * From table_name order by field1, orderby field2; multiple sorting
19. Exit MYSQL: exit;