MYSQL数据库基本操作语句

MYSQL为关系型数据库,所谓关系,即可以理解为表格的概念,一个关系型数据库由一个或者数个表格组成

表头header

行row

列col

值value

键key

数据库database

 

连接数据库:

mysql   -host(主机名)   -u(用户名)  -p(登录密码,为空则忽略此项)

 

创建一个数据库

create  database +数据库名(samp_db) 【其他选项】

createdatabase samp_db character set gbk 

创建一个叫sanmp_db的数据库并设置编码为gbk

 

创建数据库表

create table +表名称(列声明)

creattable students (

   id int unsigned not null auto_incrementprimary key,

   name char(8) not null,

   sex char(4) not null,

   age tinyint unsigned not null,

   tel char(13) null default “-”

);

 

插入数据

insert [into] 表名 [(列名1,列名2,列名3,…)] values (值1,值2,值3,…);

insertinto students values(NULL,”王刚“,”男“,20,”17625612527“);

insertinto students (name,sex,age) values (“孙丽华”,“女“,21);

 

查找数据

select 列名称 from 表名称 [查询条件];

selectname,age from students;

 

按照特定的条件查找

select 列名称 from 表名称 where 条件;

select* from students where age > 21;

select* from students where name like “%王%”

 

 

更新表中的数据

update 表名称 set 列名称=新值whiere 更新条件;

updatestudents set tel=default where id=5;

updatestudents set age=age+1;

 

删除表中的数据

deletefrom 表名称 where 删除条件;

delete f’rom students whereid=2

 

 

创建后表的修改

添加列

alter table 表名 add 列名 列数据类型 【alert插入位置】

altertable students add birthday date after age

 

修改列

alter table 表名 change列名称 列新名称 新数据类型;

altertable students change tel telphone char(13) default;

altertable students change name name char(16) not null;

 

删除列

alter table 表名 drop 列名称 ;

altertable students drop birthday

 

重命名表

alter table 表名 rename 新表名;

alter table students rename workmates;

 

删除整张表

drop table 表名;

droptable workmates

 

删除整个数据库

drop databases 数据库名称;

dropdatabases samp_db;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值