免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2140 | 回复: 0
打印 上一主题 下一主题

常用数据库操作命令 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-08 09:19 |只看该作者 |倒序浏览
drop databases if exists school; //如果存在school则删除
create database school;  //建立库school
use school;   //打开库school
create table student  //建立表student
(
id int(3) auto_increment not null primary key,
name char(10) no null,
age int(2),
sex char(2)
);
//插入数据
insert into student values('','jack','22','男');
//修改数据
update student set name='Sean' where name='jack';
//修改表名
alter table student rename to Student;
alter table student rename as Student;
//添加列
alter table student add birthday date;
//删除列
alter table student drop birthday;
//加索引
create index 索引名 on 表名(字段名)
//修改字段名
alter table student change age Age int(8);
//修改字段类型
alter table student change name varchar(20);
alter table student modify name varchar(20);
//备份表
mysqldump -u root -p school student >student.bak;
//导出数据
select name age from student into outfile "/home/mysql/temp.txt";
//导入数据
load data infile "/home/mysql/temp.txt" into table 表名;

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/107531/showart_2113602.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP