看起来相当牛逼的里程碑版本MYSQL8.0 安装及性能测试

最近MySQL算是给了一个大福利,出了MySQL8.0:

1,新版本有哪些nb的地方呢?先看看,具体性能表现如何待验证。

       

  - 事务性数据字典,完全脱离了 MyISAM 存储引擎

  - utf8mb4 字符集将成为默认字符集,并支持 Unicode 9

  - InnoDB enhancements. innodb性能提升

  - 

2,为什么直接从5.7飞到了8.0?

可参考:

-  With version 8.0, MySQL is jumping several versions in its numbering (from 5.5), due to 6.0 being nixed (混合型) and 7.0 being reserved for the clustering(为集群保留) version of MySQL. 

 (What’s new in MySQL 8.0   https://www.infoworld.com/article/3228154/sql/whats-new-in-mysql-80.html

- 事实上,MySQL 5.x 系列已经延续了很多年,从被 Oracle 收购之前就是 5.1,而收购之后一直维持在 5.x,比如 5.5,5.6,5.7 等等。其实,如果按照原本的发布节奏,可以把 5.6.x 当成 6.x,5.7.x 当成 7.x。所以,只是换了版本命名方式而已。

(知乎:MySQL 8.0.0 发布  https://zhuanlan.zhihu.com/p/22476127) 

 

 3,性能测试:

  INSERT 插入

SSD下多个表的数据插入,这里测试了数据引擎myisam跟innodb,总体来说插入的效率仍然是myisam获胜,在同时插入5000个表(每个表4列,主要是时间,整型变量等),innodb需3分多钟,而myisam只需要1分钟不到;当然这跟他们的存储机制相关,myisam直接内存上,而innodb需写入磁盘log后再执行。(具体可参考:https://stackoverflow.com/questions/9744053/mysql-innodb-vs-myisam-inserts)

下图是myisam下的测试结果:

    

 

如果业务只关心插入效率,那么关于insert我们还能做什么优化吗? 这里MySQL8.0 官方给出了一些建议: https://dev.mysql.com/doc/refman/8.0/en/insert-optimization.html ;

  首先,我们需要理解,在插入执行的整个过程中,有这样一些关键的时间点(数字代表所占的比例):

  • Connecting: (3) 
  • Sending query to server: (2)
  • Parsing query: (2)
  • Inserting row: (1 × size of row)
  • Inserting indexes: (1 × number of indexes)
  • Closing: (1)

 

    然后,选择合适的提升方式:

  • If you are inserting many rows from the same client at the same time, use INSERT statements with multiple VALUES lists to insert several rows at a time. This is considerably faster (many times faster in some cases) than using separate single-row INSERT statements. If you are adding data to a nonempty table, you can tune the bulk_insert_buffer_size variable to make data insertion even faster. See Section 5.1.7, “Server System Variables”.

一来如上图所示,采用多个value的形式,同一个表一次多行数据提交,因为减少了提交次数,这个写入效率有很明显的提高;另外当对一个非空表进行插入时,也可以通过修改bulk_insert_buffer_size,来提高写入效率。MyISAM  对于大体积的打包写入更快,如INSERT ... SELECT, INSERT ... VALUES (...), (...), ..., and LOAD DATA INFILE 。

- 关于bulk_insert_buffer_size, This variable limits the size of the cache tree in bytes per thread. Setting it to 0 disables this optimization. The default value is 8MB.

bulk_insert_buffer_size 的默认值是8MB:

   

 

      用LOAD DATA INFILE从txt文件中加载表格,通常会比insert快20倍 (666666666)。

 

  • Take advantage of the fact that columns have default values. Insert values explicitly only when the value to be inserted differs from the default. This reduces the parsing that MySQL must do and improves the insert speed.

 充分利用默认值, 充分利用默认值, 充分利用默认值 (因为减少了插入值的解析时间);

 

通过disable一些功能,比如autocommit模式,唯一性检测unique_checks,外键foreign_key_checks,或者修改一些参数,如innodb_autoinc_lock_mode 等; 具体可参阅, https://dev.mysql.com/doc/refman/8.0/en/optimizing-innodb-bulk-data-loading.html 。

 

    有一种情况,例如有数据表拥有多个用户同时写入:

    • Connection 1 does 1000 inserts
    • Connections 2, 3, and 4 do 1 insert
    • Connection 5 does 1000 inserts

如果没使用锁 连接2,3,4 会因为写入量少会先于1,5完成;但是使用锁的话情况则不一定,但总的写入时间会快40%以上。另外,修改配置都是可以提高的方法,如key_buffer_size,默认8MB,如果电脑只跑MySQL, MyISAM存储,那么这个参数key_buffer_size可以设置为内存的四分之一,千万别太大,千万别太大,千万别太大!!!

key_buffer_size参考:   https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_key_buffer_size  

大体积MyISAM写入,具体可参考: https://dev.mysql.com/doc/refman/8.0/en/optimizing-myisam-bulk-data-loading.html

 

  INSERT 总结

  如果你只关心写入效率,那么myisam会胜过innodb,组合提交的效率会高不少,适当根据电脑性能及操作系统修改相关配置也有一定的提升,根据不同业务在写入时加锁或利用数据库的默认值也是不错的方法。

  暂时还没试 load_data_infile,看起来性能似乎比myisam更好,欢迎分享。

  


 

 

 

posted @ 2018-04-24 12:47  Nengka  阅读(6241)  评论(0编辑  收藏  举报