mysql

1: 测试 C:\Program Files\MySQL\MySQL Server 5.5\my.ini

 

delimiter //    // 这是在dos命令下 - 多行执行

 

退出mysql :  exit   quit

刷新系统权限: flush   privileges

 

mysql显示列的信息

describe 简写desc  desc table_name 或explain table_name   或 show columns from table_name显示列的信息

 显示所有表 show tables;

显示所有数据库 show databases;

 

修改表列的结构

alter table table_name modify  列名 类型 是否为空

alter table table_name change column_name columnName type is not null?

修改表的字符集

alter  table  table_name  default   charset  gbk;

 

设置字符

set  charset utf8/gbk;

设置缓存大小

set  GloBal query_cache_size = 41984

显示缓存大小

show variables  like 'query_cache_size

 

 

添加外键约束

alter   table  表名 add  constraint   约束名   foreign  key  外键字段 references  表名(字段名)

 

按月统计

date_format(时间字段 ,  '%m')

 

将字符串转换为时间类型 函数str_to_date %Y-%m-%d %H:%i:%s

将int转换为varchar  用concat

将varchar转换为int  用cast(a   as   signed)

 

函数问题

group_concat  默认长度为1024   超过会被截断

show  variables  like  '%group%'

代码设置 set   session   group_concat_max_len = 1024

或在my.ini 添加group_concat_max_len = 1024

 

时间函数 date_format(date  , format)

%M   月名字(January ...  December)

%W   星期名字(Sunday ...  Saturday)

 %Y 年数字 4位数

%y 年数字 2位数

%U (00-53) 星期日是一周的第一天

%u(00-53)星期一是一周的第一天

%m 月 数字(01----12)

%c 月 数字(1-------12)

按天 周 月分组

  1. select DATE_FORMAT(create_time,'%Y%u') weeks,count(caseid) count from tc_case group by weeks;  
  2. select DATE_FORMAT(create_time,'%Y%m%d') days,count(caseid) count from tc_case group by days;  
  3. select DATE_FORMAT(create_time,'%Y%m') months,count(caseid) count from tc_case group by months;

 

 

 强制使用索引

FORCE INDEX(索引名)

 

优化经验

如果你的排序来自于两张表的字段,那么,mysql无法帮你优化,索引也没有

 

比如,a.id desc,b.id asc
这样,就算id有索引,mysql也不会用!甚至这样的排序,你无法让mysql用索引

 

 测试

select * from table where 1=1 limit 100,20;

select * from table where id <=(
select id from table order by id desc limt 100,1
) order by id desc limit 20

 


插入多条记录

---- insert into table() values(),(),()

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值