mysql 简单使用
2016-04-29 14:35
471 查看
Mysql使用(下载mysql workbench 工具,官方下载)
1. 登录:mysql –u root –p
2. 创建数据库 create database donwu
3. 使用数据库 use donwu;
4. 创建表 :createtable 表名称(列声明);
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. 查询:
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;
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;
相关文章推荐
- mysql rc模式时binlog_format=row的解释【转】
- Mysql中的排序规则utf8_unicode_ci、utf8_general_ci的区别总结
- mybatis/JDBC读取mysql数据库中CHAR(1)类型数据为空
- MySQL之alter语句用法总结
- mysql外键创建失败的问题
- MySQL 读写分离介绍及搭建
- MySQL多表删除
- mysql thread_cache 和 thread_pool 之间的关系
- MySQL数据库 表的基本操作
- mysql
- MYSQL 好文章集锦
- 怎样把MySQL的编码方式改为utf8?
- tornado中使用celery实现异步MySQL操作
- Mysql查询语句优化技巧
- MySQL中函数CONCAT及GROUP_CONCAT
- mysql 常用命令
- mysql查询优化技巧
- MySQL5.7重置 root 密码
- MySQL创建用户与授权方法
- mysql一主多从同步配置