当前位置: 移动技术网 > IT编程>数据库>Mysql > MySql 学习(一)

MySql 学习(一)

2018年09月13日  | 移动技术网IT编程  | 我要评论

入门使用

  1 show databases;
  2 
  3 //假设存在seckill 数据库
  4 use seckill;
  5 
  6 //查看所有表
  7 show tables;
  8 
  9 //查看某个表的字段,例如存在 student 表
 10 desc  student;
 11 
 12 //查看student 数据
 13 selet * from student
 14 
 15 //接下来就可以对这个数据库(seckill)作各种操作了,select 啊,update ...%&*$^$^ 巴拉巴拉的

创建表格

  1 //指定主键
  2 create table permission (
  3 	permission_id int(11) not null auto_increment,
  4 	available int not null,
  5 	description char(20) null,
  6 	permission int(20) not null,
  7 	url char(20) not null,
  8 	primary key(permission_id)
  9 )engine = innodb default charset=utf8 auto_increment=1;
  1 //指定外键
  2 create table role_permission (
  3 	role_id int(11) not null ,
  4 	permission_id int(11) not null ,
  5 	foreign key(permission_id) references permission(permission_id),
  6 	foreign key(role_id) references sys_role(role_id)
  7 )engine = innodb default charset=utf8 ;
  8 

数据结构

(1)串数据类型(如名字,地址,电话号码,邮政编码等)

          分为定长串和变长串,char : 定长, text : 变长 ,mysql处理定长数据快于处理变长数据,此外,mysql不允许对变长列(或一个列的可变部分)进行索引,这也会极大地影响性能。

  • char: 1~255 个字符的定长字符串,未指定为char(1)
  • varchar : 变长字符串,最多不超过255字节
  • text : 最大长度为 64字节的变长文本
  • tingtext : 与text相同,最大长度为255字节

  (2)数字数据类型

            所有数据类型都有有符号和无符号之分(除bit 和 boolean), 默认为有符号(即是可以表示负数),若是不想表示负数,可以使用unsigned关键字。

  • bit : 1~64 位,位字段
  • boolean : 布尔值
  • decimal : 精度可变的浮点值
  • double
  • float
  • int
  • real
  • smallint
  • tinyint
  • mediumint

(3)时间和日期数据类型

  • date :  格式为 yyyy-mm-dd ,例如:2018-08-06
  • datetime :
  • timestamp
  • time :格式为hh:mm:ssconfused smile
  • year : 用4位数字表示,范围是 1901~2155年

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网