mysql(一)

mysql(一)

连接数据库

windwos下
#127.0.0.1是本机地址 也可以进行远程连接

mysql -h127.0.0.1 -P3306 -uroot -p

mysql常用数据类型

整形
  1. INT (int)
  2. SMALLINT (smallint)
  3. MEDIUMINT (mediumint)
  4. BIGINT (bigint)
typeStorageMinumun ValueMaximum Value
(Bytes)(Signed/Unsigned)Signed/Unsigned)
tinyint1-128127
smallint2-3276832768
mdeiument3-83886088388607
int4-21474836482147483647
bigint8-92233720368547758089223372036854775807
浮点型
属性存储空间精度精确性
Float4 bytes单精度非精确
Double8 bytes双精度比Float精度高
字符创

1.char
2.varchar

  • CAHR与VARCHAR

CHAR和VARCHAR存储的单位都是字符
CHAR存储定长,容易造成空间的浪费
VARCHAR存储变长,节省存储空间

  • TEXT与CHAR和VARCHAR的区别

CHAR和VARCHAR存储单位为字符
TEXT存储单位为字节,总大小为65535字节,约为64KB
CHAR数据类型最大为255字符
VARCHAR数据类型为变长存储,可以超过255个字符
TEXT在MySQL内部大多存储格式为溢出页,效率不如CHAR

常用命令
#展示所有数据库
show databases;
#使用名为testdao的数据库
use testdao;
#展示testdao数据库中的所有表
show tables;
#创建表,表名为stu;
#写法不唯一,如果用的表名和字段名是关键字,要用``包含
create table stu1(
id int(10) auto_increment primary key comment "id",
name varchar(20) ,
score int(10) 
)engine=innodb default charset=utf8;
# 查看创建好的表
show create table stu1;
#产看表的结构
desc stu1;
#添加一个age字段
alter table stu1 add column age int(10);
#将score的默认值设为0;
alter table stu1 alter column score  set default 0;
# 修改一个字段
alter table stu modify column age int(40);
# 删除一个字段
alter table stu drop column int;
#插入一行数据,可以插入全部的字段,也可以只有某些字段
insert into stu1 value(1,"zxc",90,13);
insert into stu1(name,age) value("zdy",12);
# 删除表中的数据
delete from stu1 where id=2;
#删除空字段
delete from stu1 where age is null;
# 更新语句
update stu1 set age=29 where id=1;
#查找数据
select name,age,score from stu1 where id=1;
#删除表
drop stu1;

( 于2016年6月18日,http://blog.csdn.net/bzd_111

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值