`CREATE DATABASE database_name;` - 创建新的数据库。
`USE database_name;` - 选择要使用的数据库。
`SHOW DATABASES;` - 列出所有数据库。
`DROP DATABASE database_name;` - 删除数据库。
`CREATE TABLE table_name (column definitions);` - 创建新表。
`ALTER TABLE table_name ADD column_name datatype;` - 添加新列。
`ALTER TABLE table_name DROP column_name;` - 删除列。
`ALTER TABLE table_name MODIFY column_name datatype;` - 修改列的属性。
`DROP TABLE table_name;` - 删除表。
`INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,...);` - 插入新记录。
`UPDATE table_name SET column1=value1, column2=value2,... WHERE some_column=some_value;` - 更新现有记录。
`DELETE FROM table_name WHERE some_column=some_value;` - 删除记录。
`SELECT * FROM table_name;` - 选择表中的所有记录。
`SELECT column1, column2,... FROM table_name;` - 选择表中的指定列。
`SELECT * FROM table_name WHERE some_column=some_value;` - 根据条件选择记录。
`SELECT COUNT(column_name), AVG(column_name), MAX(column_name), MIN(column_name), SUM(column_name) FROM table_name;` - 使用聚合函数。
`SELECT DISTINCT column_name FROM table_name;` - 返回没有重复值的列。
`SELECT * FROM table_name ORDER BY column_name [ASC|DESC];` - 排序输出结果。
`SELECT * FROM table_name LIMIT [start,] number_of_records;` - 限制结果集的数量。
`SELECT * FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name = table_name2.column_name;` - 连接两个表。
`SELECT * FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name = table_name2.column_name;` - 左连接。
`SELECT * FROM table_name1 RIGHT JOIN table_name2 ON table_name1.column_name = table_name2.column_name;` - 右连接。
`SELECT * FROM table_name1 FULL OUTER JOIN table_name2 ON table_name1.column_name = table_name2.column_name;` - 全连接。
SELECT COUNT(*) as number_of_students FROM grades GROUP BY score;- 统计不同成绩的学生人数。
SELECT * FROM table_name WHERE column_name BETWEEN A AND B;-查找A与B之间的数据
`SELECT column_name(s) FROM table_name WHERE column_name operator (SELECT column_name FROM table_name WHERE condition);` - 在WHERE子句中使用子查询。
`SELECT column_name(s) FROM table_name WHERE column_name IN (SELECT column_name FROM table_name);` - 使用IN关键字。
`SELECT column_name(s) FROM table_name WHERE column_name NOT IN (SELECT column_name FROM table_name);` - 使用NOT IN关键字。
`CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition;` - 创建视图。
`DROP VIEW view_name;` - 删除视图。
`START TRANSACTION;` - 开始事务。
`COMMIT;` - 提交事务。
`ROLLBACK;` - 回滚事务。
`GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';` - 授予权限。
`REVOKE ALL PRIVILEGES ON database_name.* FROM 'username'@'localhost';` - 撤销权限。
`FLUSH PRIVILEGES;` - 刷新权限缓存。
`CREATE INDEX index_name ON table_name (column_list);` - 创建索引。
`DROP INDEX index_name ON table_name;` - 删除索引。