mysql(一)

来源:互联网 发布:华3交换机端口激活命令 编辑:程序博客网 时间:2024/05/21 15:23

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)
type Storage Minumun Value Maximum Value (Bytes) (Signed/Unsigned) Signed/Unsigned) tinyint 1 -128 127 smallint 2 -32768 32768 mdeiument 3 -8388608 8388607 int 4 -2147483648 2147483647 bigint 8 -9223372036854775808 9223372036854775807

浮点型

属性 存储空间 精度 精确性 Float 4 bytes 单精度 非精确 Double 8 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
原创粉丝点击