mysql数据库命令大全
时间: 2023-09-20 16:07:50 浏览: 67
以下是常用的 MySQL 命令:
1. 登录 MySQL:`mysql -u username -p`
2. 显示所有数据库:`show databases;`
3. 创建数据库:`create database database_name;`
4. 删除数据库:`drop database database_name;`
5. 选择数据库:`use database_name;`
6. 显示所有表格:`show tables;`
7. 创建表格:`create table table_name (column1 datatype, column2 datatype, column3 datatype, ...);`
8. 删除表格:`drop table table_name;`
9. 插入数据:`insert into table_name (column1, column2, column3, ...) values (value1, value2, value3, ...);`
10. 更新数据:`update table_name set column1 = value1, column2 = value2, ... where some_column = some_value;`
11. 删除数据:`delete from table_name where some_column = some_value;`
12. 查询数据:`select * from table_name;`
13. 查询指定列:`select column1, column2, ... from table_name;`
14. 排序数据:`select * from table_name order by column_name asc/desc;`
15. 过滤数据:`select * from table_name where some_column = some_value;`
16. 模糊查询:`select * from table_name where column_name like '%some_value%';`
17. 统计数据:`select count(*) from table_name;`
18. 去重数据:`select distinct column_name from table_name;`
19. 多表查询:`select * from table1 join table2 on table1.column_name = table2.column_name;`
20. 导出数据:`mysqldump -u username -p database_name > backup.sql`
21. 导入数据:`mysql -u username -p database_name < backup.sql`
阅读全文