随笔分类 -  python

摘要:16进制串转字节串: bytes().fromhex('010210') ==> b'\x01\x02\x10' 16进制数组转字节串: bytes([0x01,0x02,0x31,0x32]) ==> b'\x01\x0212' 字节串转16进制表示,固定两个字符表示: str(binascii. 阅读全文
posted @ 2018-10-31 11:38 Claire_xu 阅读(590) 评论(0) 推荐(0)
摘要:http协议通信需要httpServer和httpClient. 在python中 -- httpServer的实现类是server.py文件,要跟实现tcp,udp Server的文件socketserver.py区分开。 server.py中实现了HTTPServer, 还有一些Handler。 阅读全文
posted @ 2018-07-18 15:06 Claire_xu 阅读(2977) 评论(0) 推荐(0)
摘要:- select * from userinfo limit 20000,10 # 数据越往后越慢 - 索引表中扫: select * from userinfo where id in (select id from userinfo limit 20000,10) # 也慢 - select * 阅读全文
posted @ 2018-03-29 19:39 Claire_xu 阅读(93) 评论(0) 推荐(0)
摘要:DBA工作:通过日志找到执行慢的sql语句 慢日志: - 执行时间 > 10 - 未命中索引 配置: - 基于内存 show variables like '%query%'; set global 变量名 = 值 - 基于配置文件 mysqld --defaults-file = '配置文件路径+ 阅读全文
posted @ 2018-03-29 19:30 Claire_xu 阅读(269) 评论(0) 推荐(0)
摘要:explain + sql语句 返回的type类型有 all 全表扫描(特殊的有limit),type为此类型时,表示该表可以优化 index 全索引扫描 range 对索引列进行范围查找 index_merge 合并索引,使用多个单列索引 ref 根据索引查找一个或多个值 eq_ref 连接时使用 阅读全文
posted @ 2018-03-29 19:21 Claire_xu 阅读(125) 评论(0) 推荐(0)
摘要:select * from (select * from tb where id<10) as B 阅读全文
posted @ 2018-03-25 17:32 Claire_xu 阅读(148) 评论(0) 推荐(0)
摘要:备份数据表结构+数据 mysqldump -u root -p db1 > db1.sql 只备份数据表结构 mysqldump -u root -p -d db1 > db1.sql 还原数据表 mysqldump -u root -p db2 < db1.sql 阅读全文
posted @ 2018-03-25 17:13 Claire_xu 阅读(117) 评论(0) 推荐(0)
摘要:1 在 https://dev.mysql.com/downloads/mysql/ 上下载mysql压缩包 2 解压,并把bin目录加入环境变量 3 初始化,完成后会在mysql根目录下生成data目录 mysqld --initialize-insecure 4 启动mysql服务器: mysq 阅读全文
posted @ 2018-03-25 09:33 Claire_xu 阅读(674) 评论(0) 推荐(0)
摘要:作用: - 约束 - 加速查找 普通索引:加速查找 create index 索引名称 on 表名(列名,) drop index 索引名称 on 表名 主键索引:加速查找+不能为空+不能重复 create unique index 索引名称 on 表名(列名) drop unique index 阅读全文
posted @ 2018-03-15 18:05 Claire_xu 阅读(140) 评论(0) 推荐(0)
摘要:date_format函数 阅读全文
posted @ 2018-03-15 17:45 Claire_xu 阅读(278) 评论(0) 推荐(0)
摘要:视图 # 视图也是一张表,但在data文件里只有表结构,没有表数据 # 不建议使用,扩展性差,程序需改变时,依赖的视图也要改变 # 视图牵涉到多张表时,视图中的记录不能修改。 create view course2teacher as select * from course inner join 阅读全文
posted @ 2018-03-15 17:22 Claire_xu 阅读(198) 评论(0) 推荐(0)
摘要:创建本地账号 create user 'egon1'@'localhost' identified by '123'; # mysql -uegon1 -p123 创建远程账号 create user 'egon2'@'192.168.31.10' identified by '123'; # my 阅读全文
posted @ 2018-03-15 14:08 Claire_xu 阅读(275) 评论(0) 推荐(0)
摘要:内连接 select * from employee inner join department on employee.dep_id = department.id 左连接 在内连接的基础上保留左表记录 select * from employee left join department on 阅读全文
posted @ 2018-03-14 11:14 Claire_xu 阅读(437) 评论(0) 推荐(0)
摘要:select * from employee where name regexp '^jin' select * from employee where name regexp '^jin.*(g|n)$' select * from employee where name = 'a_' # _代表 阅读全文
posted @ 2018-03-14 11:04 Claire_xu 阅读(1622) 评论(0) 推荐(0)
摘要:语法顺序: select distinct 字段1,字段2,字段3 from 库.表 where 条件 group by 分组条件 having 过滤 # 执行顺序的话,到这步会返回运行select语句,之后再运行order by order by 排序字段 limit n; # 限制打印到屏幕上的 阅读全文
posted @ 2018-03-14 11:02 Claire_xu 阅读(360) 评论(0) 推荐(0)
摘要:多对一 : 只需设个外键 外键变种之一对一:普通外键关联的表是一对多关系,如果外键上再加上唯一索引,表就会变成一对一关系。 外键变种之多对多: 阅读全文
posted @ 2018-03-13 17:49 Claire_xu 阅读(191) 评论(0) 推荐(0)
摘要:not null约束,需设置默认值 sex enum('male','female') not null default 'male' unique 约束,值唯一 单列唯一: create table department( id int unique, name char(10) unique); 阅读全文
posted @ 2018-03-13 17:14 Claire_xu 阅读(785) 评论(0) 推荐(0)
摘要:整形类型:该类型没必要指定显示宽度,使用默认的就ok。 类型 大小 TINYINT 1字节 SMALLINT 2字节 MEDIUMINT 3字节 INT或INTEGER 4字节(后面加的宽度不是存储宽度,而是显示宽度) create table t5(id int(5) unsigned zerof 阅读全文
posted @ 2018-03-13 16:36 Claire_xu 阅读(726) 评论(0) 推荐(0)
摘要:表的类型就是存储引擎。如CSV,InnoDB,MEMORY,BLACKHOLE等。 在Oracle 和SQL Server等数据库中只有一种存储引擎,所有数据存储管理机制都是一样的。而MySql数据库提供了多种存储引擎。 用户可以根据不同的需求为数据表选择不同的存储引擎,用户也可以根据自己的需要编写 阅读全文
posted @ 2018-03-12 17:53 Claire_xu 阅读(528) 评论(0) 推荐(0)
摘要:sql语言分3种类型: 1 DDL语句 数据库定义语句:数据库、表、视图、索引、存储过程,例如CREATE DROP ALTER 2 DML语句 数据库操纵语言:插入删除更新查询数据,INSERT DELETE UPDATE SELECT 3 DCL语句 数据库控制语言:例如控制用户的访问权限GRA 阅读全文
posted @ 2018-03-12 17:26 Claire_xu 阅读(146) 评论(0) 推荐(0)