建表语句

CREATE TABLE staffs(
id INT PRIMARY KEY AUTO_INCREMENT,
NAME VARCHAR (24) NOT NULL DEFAULT '' COMMENT '姓名',
age INT NOT NULL DEFAULT 0 COMMENT '年龄',
pos VARCHAR (20) NOT NULL DEFAULT 0 COMMENT '职位',
add_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入职时间'
) CHARSET utf8 COMMENT '员工记录表'; INSERT INTO staffs(NAME, age, pos, add_time) VALUES('ronnie', 22, 'manager', NOW());
INSERT INTO staffs(NAME, age, pos, add_time) VALUES('John', 23, 'devloper', NOW());
INSERT INTO staffs(NAME, age, pos, add_time) VALUES('2181', 27, 'devloper', NOW()); -- 建复合索引
alter table staffs add index idx_staffs_nameAgePos(name, age, pos);

mysql 优化法则

  1. 全值匹配我最爱(Kappa)

  2. 遵循最佳左前缀法则

    • 如果索引了多列, 查询从索引的最左前列开始并且不跳过索引中的列。

    • 其实索引本质是个单向链表, 你要先得到头才能逐渐往后取后面的, 中间断了就走不了后面的索引了。

    • 正确使用 Demo:

      mysql> explain select * from staffs where name = 'ronnie';
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-------+
      | 1 | SIMPLE | staffs | NULL | ref | idx_staffs_nameAgePos | idx_staffs_nameAgePos | 74 | const | 1 | 100.00 | NULL |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where name = 'ronnie' and age = 22;
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------------+------+----------+-------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------------+------+----------+-------+
      | 1 | SIMPLE | staffs | NULL | ref | idx_staffs_nameAgePos | idx_staffs_nameAgePos | 78 | const,const | 1 | 100.00 | NULL |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------------+------+----------+-------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where name = 'ronnie' and age = 22 and pos = 'manager';
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------------------+------+----------+-------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------------------+------+----------+-------+
      | 1 | SIMPLE | staffs | NULL | ref | idx_staffs_nameAgePos | idx_staffs_nameAgePos | 140 | const,const,const | 1 | 100.00 | NULL |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------------------+------+----------+-------+
      1 row in set, 1 warning (0.00 sec)
    • 违反使用Demo:(完全失效)[带头大哥死了]:

      mysql> explain select * from staffs where age = 22 and pos = 'manager';
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | NULL | NULL | NULL | NULL | 3 | 33.33 | Using where |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where age = 22;
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | NULL | NULL | NULL | NULL | 3 | 33.33 | Using where |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where pos = 'manager';
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | NULL | NULL | NULL | NULL | 3 | 33.33 | Using where |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec)
      • 完全失效, 执行了全表扫描。
    • 违反使用Demo(部分失效)[中间兄弟断了]:

      mysql> explain select * from staffs where name = 'ronnie' and pos = 'manager';
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-----------------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-----------------------+
      | 1 | SIMPLE | staffs | NULL | ref | idx_staffs_nameAgePos | idx_staffs_nameAgePos | 74 | const | 1 | 33.33 | Using index condition |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-----------------------+
      1 row in set, 1 warning (0.00 sec)
      • 使用了复合索引 idx_staffs_nameAgePos, 但 reference 只有一个常量参数, 只用了最左侧的 name, 没用到 pos。
  3. 不在索引列上做任何操作(计算、函数、(自动 or 手动) 类型转换), 会导致索引失效而转向全表扫描

    • 索引列上执行函数Demo:

      mysql> explain select * from staffs where left(name,4) = 'John';
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | Using where |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec)
      • 可以看到执行了全表扫描, 索引失效。
    • 索引列上执行计算Demo:


      mysql> explain select * from staffs where char_length('name') > 3;
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------+
      | 1 | SIMPLE | staffs | NULL | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | NULL |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------+
      1 row in set, 1 warning (0.00 sec)
      • 可以看到执行了全表扫描, 索引失效。
    • 索引列上执行类型转换Demo:

      mysql> select * from staffs where name = 2181;
      +----+------+-----+----------+---------------------+
      | id | NAME | age | pos | add_time |
      +----+------+-----+----------+---------------------+
      | 3 | 2181 | 27 | devloper | 2020-01-10 11:38:08 |
      +----+------+-----+----------+---------------------+
      1 row in set, 2 warnings (0.00 sec) mysql> explain select * from staffs where name = 2181;
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | idx_staffs_nameAgePos | NULL | NULL | NULL | 3 | 33.33 | Using where |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      1 row in set, 3 warnings (0.00 sec) mysql> explain select * from staffs where name = '2181';
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-------+
      | 1 | SIMPLE | staffs | NULL | ref | idx_staffs_nameAgePos | idx_staffs_nameAgePos | 74 | const | 1 | 100.00 | NULL |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-------+
      1 row in set, 1 warning (0.00 sec)
      • 这种就是比较坑的, 平时写sql是不注意, varChar类型请务必加上' ', 如果不加, mysql底层会进行类型的隐式转换, 造成索引失效。
  4. 存储引擎不能使用索引中范围条件右边的列

    • 范围之后全失效, 所以建索引是一门学问, 需要对常用的业务sql进行综合考量。

    • Demo:

      mysql> explain select * from staffs where name = 'John' and age > 22 and pos = 'devloper';
      +----+-------------+--------+------------+-------+-----------------------+-----------------------+---------+------+------+----------+-----------------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+-------+-----------------------+-----------------------+---------+------+------+----------+-----------------------+
      | 1 | SIMPLE | staffs | NULL | range | idx_staffs_nameAgePos | idx_staffs_nameAgePos | 78 | NULL | 1 | 33.33 | Using index condition |
      +----+-------------+--------+------------+-------+-----------------------+-----------------------+---------+------+------+----------+-----------------------+
      1 row in set, 1 warning (0.00 sec)
      • 我们的索引是这样建的: name -> age -> pos

      • 由于中间的age进行了范围查询, 会导致后续的索引全部失效。

  5. 尽量使用覆盖索引(只访问索引的查询(索引列和查询列一致)), 减少select *

    • 对比Demo:

      mysql> explain select * from staffs where name = 'John' and pos = 'devloper';
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-----------------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-----------------------+
      | 1 | SIMPLE | staffs | NULL | ref | idx_staffs_nameAgePos | idx_staffs_nameAgePos | 74 | const | 1 | 33.33 | Using index condition |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+-----------------------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select name, age, pos from staffs where name = 'John' and pos = 'devloper';
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+--------------------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+--------------------------+
      | 1 | SIMPLE | staffs | NULL | ref | idx_staffs_nameAgePos | idx_staffs_nameAgePos | 74 | const | 1 | 33.33 | Using where; Using index |
      +----+-------------+--------+------------+------+-----------------------+-----------------------+---------+-------+------+----------+--------------------------+
      1 row in set, 1 warning (0.00 sec)
      • 可以看到extra多了 Using index, 表面select操作中使用了覆盖索引(Covering Index), 避免了访问表的数据行。
  6. mysql 在使用不等于(!= 或者 <>) 的时候无法使用索引会导致全表扫描

    • Demo:

      mysql> explain select * from staffs where name != 'John';
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | idx_staffs_nameAgePos | NULL | NULL | NULL | 3 | 66.67 | Using where |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where name <> 'John';
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | idx_staffs_nameAgePos | NULL | NULL | NULL | 3 | 66.67 | Using where |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec)
  7. is null, is not null 也无法使用索引

    • 底层原因是: null 不能转换为索引表示的数字来索引

    • Demo:

      mysql> explain select * from staffs where name is null;
      +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+------------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+------------------+
      | 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE |
      +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+------------------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where name is not null;
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | idx_staffs_nameAgePos | NULL | NULL | NULL | 3 | 66.67 | Using where |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec)
  8. like 以通配符开头('%abc...') mysql 索引失效会变成全表扫描的操作

    • Demo:

      mysql> explain select * from staffs where name like '%ronnie';
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | NULL | NULL | NULL | NULL | 3 | 33.33 | Using where |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where name like '%ronnie%';
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | NULL | NULL | NULL | NULL | 3 | 33.33 | Using where |
      +----+-------------+--------+------------+------+---------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where name like 'ronnie%';
      +----+-------------+--------+------------+-------+-----------------------+-----------------------+---------+------+------+----------+-----------------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+-------+-----------------------+-----------------------+---------+------+------+----------+-----------------------+
      | 1 | SIMPLE | staffs | NULL | range | idx_staffs_nameAgePos | idx_staffs_nameAgePos | 74 | NULL | 1 | 100.00 | Using index condition |
      +----+-------------+--------+------------+-------+-----------------------+-----------------------+---------+------+------+----------+-----------------------+
      1 row in set, 1 warning (0.00 sec)
      • 可以看到只有% 在右边的查询使用了索引

      • 这个情况就比较蛋疼, 如果你们业务上就需要百分号在左边, 需要使用覆盖索引来优化。

        mysql> explain select id, name from staffs where name like '%ronnie%';
        +----+-------------+--------+------------+-------+---------------+-----------------------+---------+------+------+----------+--------------------------+
        | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
        +----+-------------+--------+------------+-------+---------------+-----------------------+---------+------+------+----------+--------------------------+
        | 1 | SIMPLE | staffs | NULL | index | NULL | idx_staffs_nameAgePos | 140 | NULL | 3 | 33.33 | Using where; Using index |
        +----+-------------+--------+------------+-------+---------------+-----------------------+---------+------+------+----------+--------------------------+
        1 row in set, 1 warning (0.00 sec)
      • 做查询如果数据量大的话 用 Lucene, Solr, ElasticSearch 不香吗?

  9. 字符串不加单引号索引失效(mysql会自己做隐式转换)

    • Demo 同3
  10. 少用or, 用它来连接时会索引失效

    • Demo:

      mysql> explain select * from staffs where name = 'John' or name = 'ronnie';
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | idx_staffs_nameAgePos | NULL | NULL | NULL | 3 | 66.67 | Using where |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where name = 'John' or age = 23;
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | idx_staffs_nameAgePos | NULL | NULL | NULL | 3 | 55.56 | Using where |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec) mysql> explain select * from staffs where name = 'John' or pos = 'manager';
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      | 1 | SIMPLE | staffs | NULL | ALL | idx_staffs_nameAgePos | NULL | NULL | NULL | 3 | 55.56 | Using where |
      +----+-------------+--------+------------+------+-----------------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.01 sec)

mysql 索引优化法则的更多相关文章

  1. MYSQL索引优化法则

    目录 一首诗送给各位: 全值匹配我最爱,最左前缀要遵守: 带头大哥不能死,中间兄弟不能断: 索引列上少计算,范围之后全失效: Like百分写最右,覆盖索引不写星: 不等空值还有or,索引失效要少用: ...

  2. mysql索引优化

    mysql 索引优化 >mysql一次查询只能使用一个索引.如果要对多个字段使用索引,建立复合索引. >越小的数据类型通常更好:越小的数据类型通常在磁盘.内存和CPU缓存中都需要更少的空间 ...

  3. Mysql 索引优化分析

    MySQL索引优化分析 为什么你写的sql查询慢?为什么你建的索引常失效?通过本章内容,你将学会MySQL性能下降的原因,索引的简介,索引创建的原则,explain命令的使用,以及explain输出字 ...

  4. 知识点:Mysql 索引优化实战(3)

    知识点:Mysql 索引原理完全手册(1) 知识点:Mysql 索引原理完全手册(2) 知识点:Mysql 索引优化实战(3) 知识点:Mysql 数据库索引优化实战(4) 索引原理知识回顾 索引的性 ...

  5. MySQL索引优化步骤总结

    在项目使用mysql过程中,随着系统的运行,发现一些慢查询,在这里总结一下mysql索引优化步骤 1.开发过程优化 开发过程中对业务表中查询sql分析sql执行计划(尤其是业务流水表),主要是查看sq ...

  6. MySQL索引优化看这篇文章就够了!

    阅读本文大概需要 5 分钟. 来源:cnblogs.com/songwenjie/p/9410009.html 本文主要讨论MySQL索引的部分知识.将会从MySQL索引基础.索引优化实战和数据库索引 ...

  7. mysql索引优化比普通查询速度快多少

    mysql索引优化比普通查询速度快多少 一.总结 一句话总结:普通查询全表查询,速度较慢,索引优化的话拿空间换时间,一针见血,所以速度要快很多. 索引优化快很多 空间换时间 1.软件层面优化数据库查询 ...

  8. mySql索引优化分析

    MySQL索引优化分析 为什么你写的sql查询慢?为什么你建的索引常失效?通过本章内容,你将学会MySQL性能下降的原因,索引的简介,索引创建的原则,explain命令的使用,以及explain输出字 ...

  9. 【ZZ】MySQL 索引优化全攻略 | 菜鸟教程

    MySQL 索引优化全攻略 http://www.runoob.com/w3cnote/mysql-index.html

随机推荐

  1. DHCP报文交互流程

    1.发现阶段,即DHCP客户机寻找DHCP服务器的阶段(DHCPdiscover) DHCP客户机以广播方式(因为DHCP服务器的IP地址对于客户机来说是未知的)发送DHCPdiscover发现信息来 ...

  2. 【PAT甲级】1048 Find Coins (25 分)(二分)

    题意: 输入两个正整数N和M(N<=10000,M<=1000),然后输入N个正整数(<=500),输出两个数字和恰好等于M的两个数(小的数字尽可能小且输出在前),如果没有输出&qu ...

  3. 关于调用接口 Connection reset 问题(使用代理调接口)

    之前调用过别的公司的接口上传数据,但是遇到个问题就是Connection reset,查阅了网上的各种资料,说什么的都有,主要意思就是说发布接口和调用接口的某些配置不一样,但是这个怎么说呢,单方面没办 ...

  4. HDFS核心类FileSystem的使用

    一.导入jar包 本次使用的是eclipse操作的,所以需要手动导入jar包 在Hadoop.7.7/share/hadoop里有几个文件夹 common为核心类,此次需要引入common和hdfs两 ...

  5. vagrant up启动centos7时出现"rsync" could not be found on your PATH. Make sure that rsyncis properly ins

    (1)问题1:"rsync" could not be found on your PATH. Make sure that rsyncis properly ins 解决方法: ...

  6. Git三招

    一.Git提交指令 git init git第一次使用在当前文件夹初始化一个git仓库,第二次不需要 git add . 把当前文件夹所有文件添加到缓存区中. 可以选特定的文件夹或文件.将后面的.改变 ...

  7. 多Python版本共存

    Python 3.4 和 3.7 共存 我的电脑上同时安装了 Python 3.4 和 Python 3.7 两个 Python 版本.现在打开终端窗口进入指定的版本. py -3.4 py -3.7 ...

  8. 使用pyinstaller打包.py程序

    使用pyinstaller打包.py程序 例如打包D:/Desktop 目录下的 filename.py 文件 打开 cmd 将目录切换至 D:/Desktop 输入命令 pyinstaller -F ...

  9. rc

    1,协同过滤. 2,协方差:用来衡量,他们的变化趋势是不是一致的. 3,皮尔逊相关系数:-1,负相关.1:正相关. 4,用皮尔逊相关系数来算相关性是最多的.

  10. PTA的Python练习题(十一)

    从 第4章-3 猴子吃桃问题 继续 1. a=eval(input()) def count(n): b=1 for i in range(n-1): b=(b+1)*2 return b print ...