mysql 简单使用

Mysql使用(下载mysql workbench  工具,官方下载)

1.      登录:mysql –u root –p

2.      创建数据库    create database donwu

3.      使用数据库 use donwu;

4.  创建表 :createtable 表名称(列声明);

create table students(

               id int unsigned not nullauto_increment primary key,

               name char(8) not null,

               sex char(4) not null,

               age tinyint unsigned not null,

               tel char(13) null default"-"

        );

5.  插入表

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

insert into students values(NULL, "王刚", "", 20, "13811371377");

6.  查询:

select name, age from students;
select * from students where age > 21;
select * from students where name like "%王%";

7.  更新表:

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

updatestudents set tel=default where id=5;

updatestudents set age=age+1;

8.  删除表:

delete from 表名称 where 删除条件;

deletefrom students where id=2;

deletefrom students where age<20;

9.  修改表:

1) 添加列:

altertable students add address char(60);

2) 修改列:

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

将 name 列的数据类型改为char(16)

3) 删除列:

alter table 表名 drop 列名称;

altertable students drop birthday;

4) 重命名:

alter table 表名 rename 新表名;

altertable students rename workmates;

5) 删除表:

drop table 表名;

droptable workmates;

6) 删除数据库:

drop database 数据库名;

dropdatabase samp_db;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值