mysql 命令备忘

虽然mysql命令平常用的不少,但是有了IDE的图形化建表、改表操作,这些mysql命令忘的很快,所以在此记录一下备忘

建表:
命令:create table <表名> ( <字段名1> <类型1> [,..<字段名n> <类型n>]);
mysql> create table MyClass(
> id int(4) not null primary key auto_increment,
> name char(20) not null,
> sex int(4) not null default '0',
> degree double(16,2));


插入数据:
命令:insert into <表名> [( <字段名1>[,..<字段名n > ])] values ( 值1 )[, ( 值n )]
如:mysql> insert into MyClass(id, name, source) values(1,'Tom',96.45),(2,'Joan',82.99), (2,'Wang', 96.59);


查询前几行数据
例如:查看表 MyClass 中前2行数据
mysql> select * from MyClass order by id limit 0,2;
或:
mysql> select * from MyClass limit 0,2;


修改表中数据:update 表名 set 字段=新值,… where 条件
mysql> update MyClass set name='Mary' where id=1;


在表中增加字段:
命令:alter table 表名 add字段 类型 其他; 
例如:在表MyClass中添加了一个字段passtest,类型为int(4),默认值为0 
mysql> alter table MyClass add passtest int(4) default '0'


更改表名:
命令:rename table 原表名 to 新表名; 
例如:在表MyClass名字更改为YouClass 
mysql> rename table MyClass to YouClass;

更新字段内容
update 表名 set 字段名 = 新内容
update 表名 set 字段名 = replace(字段名,'旧内容','新内容');


join链接查询
SELECT fields 
FROM table1 JOIN table2 
ON table1.field1=table2.field1

以上内容摘自mysql常用命令


在旧版本mysql中,对于group by允许有以下用法:

select a, b, c from table1 group by a;

但是在新版mysql中,使用以上语句会导致报错,应改为:

select a, b, c from table1 group by a, b, c;

具体的新旧版本范围不详

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值