时间:2021-07-01 10:21:17 帮助过:48人阅读
- 登录数据库
mysql -h host -u username -p password
输入密码,验证通过后:- 创建数据库
create database DB_NAME charset=utf8;- 查看数据库
show databases;- 选择数据库
use DB_NAME- 删除数据库
drop database DB_NAME;
create table [ if not exists ] table_name ( col_name data_type col_constraint, ... )

> 查看表结构
desc table_name;

> 查看详细表结构
show create table table_name \G

### 2、修改表
> 添加一列
alter table tbl_name add col_name dtype col_constraint;
修改某列
alter table tbl_name modify col_name dtype col_constraint;
删除某列
alter table tbl_name drop col_name;
修改列名
alter table tbl_name change old_col_name new_col_name dtype col_contraint;
重命名表
rename table old_tbl_name to new_tbl_name;
删除表
drop table tbl_name;
### 3、查询表
>
查询表中所有数据
select * from table_name;

消除重复行
select distinct field_name from table_name;

条件查询
// 查询id小于3的所有数据

// 查询名字不是"xiaohong"的所有数据

// 查看未删除的所有数据

// 查看id大于3且性别为女

// 查看id小于4或未删除

// 查看姓黄的所有数据

// 查看姓黄且只有两个字的所有姓名

MySQL基础(二)
标签:ons sts 条件 查询 char 基础 shadow table name