mysql 简单使用

来源:互联网 发布:淘宝食品企业店铺 编辑:程序博客网 时间:2024/06/06 20:10

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