关于MySQL密码重置
/usr/bin/mysqld_safe --skip-grant-tables >/dev/null 2>&1 &
/usr/bin/mysql -u root mysql
>update user set password = Password('root') where User = 'root';
>flush privileges;
>exit;
数据类型
- 前戏
vim /etc/my.cnf //修改mysql配置文件
ps -ef | grep mysqld | grep -v grep //使插入数据有误时报错
-课
show warmings //查看警告信息
数据类型
数值类型
#
*bit(M)位类型,M指定位数,默认1,范围1-64
* tinyint 数据范围 -127----128
tinyint unsigned 0 ---255
*bool 0和1表示真假
*smallint[unsigned]带符号-2^15到2^15-1 无符号2^16-1
*int[unsigned]带符号-2^31到2^32-1 无符号2^32-1
*bigint[unsigned]带符号-2^63到2^63-1 无符号2^64-1
*float[M,D][unsigned]m指定显示长度,d指定小数点位数,占4字节
*double[M,D][unsigned]比float精度更大的小数,占8字节
decimal[M,D][unsigned]定点数M指定长度,D表示小数位数
文本、二进制
*char
*varchar
*blob
*text
时间日期
#
data/datatime/timestamp
String类型
#
*ENUM
*SET
-无符号数减法测试
```
create table tt4 (t1 int unsigned, t2 int unsigned);
insert into tt4 values (1,2)
select t1-t2 from tt4;
结果;18446744073709551615
- 最好不要用无符号数
```
bit()
# 范围1-64 bit 字段显示时,按ASCII码对应的值显示
float
float(m,d) m宽度,d 小数位数 有四舍五入 float(4,2) -99.991 //可存 -99.996 //不可存 .99 // 也可以存
decimal
decimal (m,d)[unsigned] m 长度,d小数点位数 精度更高//64位,比float 7位
字符串
char(l) 和 varchar(1) char(1) 定长 l 字符数 varchar(l) varchar的有效字节数是65532(有1~3个字节用于记录数据大小)l不能超过21844(汉子时65532/3) 但在数据库中每一行数据总共长度不能超过65535
日期和时间类型
timestamp update birthday set t1='2000-1-1'; //时间戳,时间会自动更新 update tt13 set t1 where 表格内容修改 数据最好用''引起来
-枚举和set
enum是单选 set是多选 数据必须是后面出现的 查找: select * from votes where gender='男'; select find_in_set('a','a,b,c') select * from votes where find_in_set('武术',hobby);
表的约束
create table tt14(id int not null); //not null,不允许数据为空。 create table tt15 (name varchar(20),age tinyint not null default 0);//自动填充 0。 commet 描述信息 在desc tt15 可以查看 -- 而注释信息,不显示 int(11) 11是指的是将来int数据的总宽度,但是超过是可以的
修改表中的数据
update tt7 set id=1.1 where id=0.99; //原来的id=0.99