MySQL数据库的CRUD基本操作! ! ! !
首先登录数据库服务器:
mysql -uroot -p
打开创建好的数据库 及表
desc t_haha
一:增! ! ! ! !
查看一下表内容 发现原来没有内容,然后我们来添加
将表中原有数据修改为我们需要的数据
update t_name set 字段1 = 新值, 字段2 = 新值 … where 条件
三:删! ! ! ! !
delete from tablename where 条件
四:改!!!!!!
表结构的修改:alter table |-- 增加新的字段 ALTER TABLE 表名 ADD 列名 列类型 约束条件; alter
table t_hero add address varchar(255); |-- 修改字段的类型 ALTER TABLE 表名
MODIFY 列名 列类型; alter table t_hero modify id bigint; |– 修改字段名称 ALTER
TABLE 表名 CHANGE 旧列名 新列名 列类型; alter table t_hero change id hero_id
int; |-- 修改表名称 ALTER TABLE 表名 RENAME 新表名; alter table t_hero rename
hero; – 第二种写法 rename table hero to t_hero;五:查!!!!!
1.查询一张表: select * from 表名;
2.查询指定字段: select 字段1,字段2,字段3….from 表名;
3.where条件查询:select 字段1,字段2,字段3 frome 表名 where 条件表达式;
例:select * from t_studect where id=1;
select * from t_student where age>22;4.带in关键字查询: select 字段1,字段2 frome 表名 where 字段 [not]in(元素1,元素2);
例: select * from t_student where age in (21,23);
select * from t_student where age not in (21,23);