您的位置:首页 > 数据库 > MySQL

mysql 简单使用

2016-04-29 14:35 471 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: