MySQL5.5 MyISAM与InnoDB引擎读写性能对比

输入图片说明 MySQL5.5 MyISAM与InnoDB引擎读写性能对比 做者:陈明乾 发布日期:2014-01-06 09:48:33html

注,测试环境 CentOS 6.4 x86_64,软件版本 MySQL 5.5.35 (MySQL 5.5最新版),下载地址:http://dev.mysql.com/downloads/mysql/5.1.html#downloads。node

1、前言 在上一篇博客中咱们测试了MySQL 5.5 的TPS与rw request /s性能指标与MySQL5.1相比性能有了较大的提高。在后面的博客中咱们又测试一下MySQL 5.1插入数据与查询数据的性能,从测试结果上看MyISAM引擎的性能要优于InnoDB引擎。在这篇博客中咱们主要来测试一下MySQL 5.5的MyISAM引擎与InnoDB引擎的插入数据与查询数据的性能并与MySQL 5.1进行对比,看看MySQL 5.5 对MyISAM与InnoDB引擎改进多少。mysql

2、概述 1.环境准备 (1).安装yum源 01. [root@node7 src]# wget http://mirrors.hustunique.com/epel/6/x86_64/epel-release-6-8.noarch.rpm 02. --2014-01-05 17:37:53-- http://mirrors.hustunique.com/epel/6/x86_64/epel-release-6-8.noarch.rpm 03. 正在解析主机 mirrors.hustunique.com... 115.156.219.152
04. 正在链接 mirrors.hustunique.com|115.156.219.152|:80... 已链接。
05. 已发出 HTTP 请求,正在等待回应... 200 OK
06. 长度:14540 (14K) [application/x-redhat-package-manager]
07. 正在保存至: “epel-release-6-8.noarch.rpm” 08. 100%[===============================================================================>] 14,540 --.-K/s in 0.09s 09. 2014-01-05 17:37:54 (165 KB/s) - 已保存 “epel-release-6-8.noarch.rpm” [14540/14540]) 10. [root@node7 src]# rpm -ivh epel-release-6-8.noarch.rpm 11. warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
12. Preparing... ########################################### [100%]
13. 1:epel-release ########################################### [100%] (2).同步时间 1. [root@node7 src]# yum install -y ntp vim man 2. [root@node7 src]# ntpdate 202.120.2.101 3. [root@node7 src]# hwclock -w 3.安装cmake 注,mysql 5.5 之后编译安装都用cmake。在make与make install的时候能够看到进度百分比,感受这一点要比configure方式要好。 1. [root@node7 src]# yum install -y cmake 4.准备mysql数据目录 1. [root@node7 data]# mkdir -pv /data/mysql 2. mkdir: 已建立目录 "/data/mysql"
3. [root@node7 data]# useradd mysql
4. [root@node7 data]# chown mysql.mysql /data/mysql/
5. [root@node7 data]# ll /data/
6. 总用量 20
7. drwx------. 2 root root 16384 8月 17 18:42 lost+found
8. drwxr-xr-x. 2 mysql mysql 4096 1月 5 09:47 mysql 5.安装相关依赖包 1. [root@node7 ~]# yum install -y autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool* openssl* 6.安装mysql 01. [root@node7 src]# tar xf mysql-5.5.35.tar.gz 02. [root@node7 src]# cd mysql-5.5.35
03. [root@node7 mysql-5.5.35]# ls
04. BUILD cmd-line-utils Docs libmysql mysys scripts strings vio
05. BUILD-CMAKE config.h.cmake extra libmysqld packaging sql support-files win
06. client configure.cmake include libservices plugin sql-bench tests zlib
07. cmake COPYING INSTALL-SOURCE man README sql-common unittest
08. CMakeLists.txt dbug INSTALL-WIN-SOURCE mysql-test regex storage VERSION 09. [root@node7 mysql-5.5.35]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/data/mysql -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 10. 上面内容省略…… 11. -- Configuring done 12. -- Generating done
13. -- Build files have been written to: /root/src/mysql-5.5.35 注,看到这几行就说明咱们的cmake配置成功了,下面咱们进行编译安装。 1. [root@node7 mysql-5.5.35]# make && make install 7.为mysql提供配置文件 01. [root@node7 mysql-5.5.35]# cp support-files/my-huge.cnf /etc/my.cnf 02. cp:是否覆盖"/etc/my.cnf"? y
03. [root@node7 mysql-5.5.35]# vim /etc/my.cnf 04. #增长下面几行配置文件 05. [client] 06. default-character-set = utf8 07. [mysqld] 08. character-set-server = utf8 09. collation-server = utf8_unicode_ci 10. datadir = /data/mysql 11. innodb_buffer_pool_size = 384M 12. innodb_file_per_table=1 8.为mysql提供启动脚本 1. [root@node7 mysql-5.5.35]# cp support-files/mysql.server /etc/init.d/mysqld 2. [root@node7 mysql-5.5.35]# chmod +x /etc/init.d/mysqld 3. [root@node7 mysql-5.5.35]# chkconfig mysqld --add 4. [root@node7 mysql-5.5.35]# chkconfig mysqld on 9.初始化mysql 01. [root@node7 mysql-5.5.35]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql 02. Installing MySQL system tables... 03. OK 04. Filling help tables... 05. OK 06. To start mysqld at boot time you have to copy 07. support-files/mysql.server to the right place for your system 08. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! 09. To do so, start the server, then issue the following commands: 10. /usr/local/mysql//bin/mysqladmin -u root pass<a href="http://www.it165.net/edu/ebg/" target="_blank" class="keylink">word</a> 'new-pass<a href="http://www.it165.net/edu/ebg/" target="_blank" class="keylink">word</a>' 11. /usr/local/mysql//bin/mysqladmin -u root -h node7.test.com password 'new-password' 12. Alternatively you can run: 13. /usr/local/mysql//bin/mysql_secure_installation 14. which will also give you the option of removing the test 15. databases and anonymous user created by default. This is 16. strongly recommended for production servers. 17. See the manual for more instructions. 18. You can start the MySQL daemon with: 19. cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe & 20. You can test the MySQL daemon with mysql-test-run.pl 21. cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl 22. Please report any problems with the /usr/local/mysql//scripts/mysqlbug script! 10.启动mysql 1. [root@node7 mysql-5.5.35]# service mysqld start 2. Starting MySQL... SUCCESS! 11.尝试登陆一下 01. [root@node7 mysql-5.5.35]# /usr/local/mysql/bin/mysql 02. Welcome to the MySQL monitor. Commands end with ; or \g.
03. Your MySQL connection id is 1
04. Server version: 5.5.35-log Source distribution 05. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 06. Oracle is a registered trademark of Oracle Corporation and/or its 07. affiliates. Other names may be trademarks of their respective
08. owners. 09. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 10. mysql> show databases; 11. +--------------------+
12. | Database |
13. +--------------------+
14. | information_schema |
15. | mysql |
16. | performance_schema |
17. | test |
18. +--------------------+
19. 4 rows in set (0.00 sec) 20. mysql> 12.输出mysql的man手册至man命令的查找路径 1. [root@node7 ~]# vim /etc/man.config 2. MANPATH /usr/local/mysql/man 13.输出mysql的头文件至系统头文件路径/usr/include 01. [root@node7 ~]# ln -sv /usr/local/mysql/include /usr/include/mysql 02. "/usr/include/mysql" -> "/usr/local/mysql/include"
03. [root@node7 ~]# cd /usr/include/mysql
04. [root@node7 mysql]# ls
05. decimal.h my_dbug.h mysqld_ername.h plugin_ftparser.h
06. errmsg.h my_dir.h mysqld_error.h plugin.h
07. keycache.h my_getopt.h mysql_embed.h sql_common.h
08. m_ctype.h my_global.h mysql.h sql_state.h
09. m_string.h my_list.h mysql_time.h sslopt-case.h
10. my_alloc.h my_net.h mysql_version.h sslopt-longopts.h
11. my_attribute.h my_pthread.h my_sys.h sslopt-vars.h
12. my_compiler.h mysql my_xml.h typelib.h
13. my_config.h mysql_com.h plugin_audit.h 14.输出mysql的库文件给系统库查找路径 1. [root@node7 ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf 2. [root@node7 ~]# ldconfig 15.修改PATH环境变量,让系统能够直接使用mysql的相关命令 01. [root@node7 ~]# vim /etc/profile.d/mysql.sh 02. export PATH=$PATH:/usr/local/mysql/bin/ 03. [root@node7 ~]# source /etc/profile 04. [root@node7 ~]# mysql
05. Welcome to the MySQL monitor. Commands end with ; or \g.
06. Your MySQL connection id is 2
07. Server version: 5.5.35-log Source distribution 08. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 09. Oracle is a registered trademark of Oracle Corporation and/or its 10. affiliates. Other names may be trademarks of their respective
11. owners. 12. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 13. mysql> 好了,到这里咱们的mysql就所有安装完成了,下面咱们来准备一下测试环境。 16.新建mydb测试库 01. mysql> create database mydb; 02. Query OK, 1 row affected (0.01 sec) 03. mysql> show databases; 04. +--------------------+
05. | Database |
06. +--------------------+
07. | information_schema |
08. | mydb |
09. | mysql |
10. | performance_schema |
11. | test |
12. +--------------------+
13. 5 rows in set (0.00 sec) 14. mysql> show create database mydb; 15. +----------+---------------------------------------------------------------------------------------+
16. | Database | Create Database |
17. +----------+---------------------------------------------------------------------------------------+
18. | mydb | CREATE DATABASE mydb /!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci / |
19. +----------+---------------------------------------------------------------------------------------+
20. 1 row in set (0.00 sec) 17.新建两测试表t1与t2,t1为MyISAM引擎、t2为InnoDB引擎 01. mysql> use mydb; 02. Database changed
03. mysql> show tables;
04. Empty set (0.00 sec) 05. mysql> CREATE TABLE t1 (id int(11) DEFAULT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8; 06. Query OK, 0 rows affected (0.01 sec) 07. mysql> CREATE TABLE t2 (id int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8; 08. Query OK, 0 rows affected (0.04 sec) 09. mysql> show tables; 10. +----------------+
11. | Tables_in_mydb |
12. +----------------+
13. | t1 |
14. | t2 |
15. +----------------+
16. 2 rows in set (0.00 sec) 17. mysql> show create table t1; 18. +-------+--------------------------------------------------------------------------------------+
19. | Table | Create Table |
20. +-------+--------------------------------------------------------------------------------------+
21. | t1 | CREATE TABLE t1 (
22. id int(11) DEFAULT NULL
23. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
24. +-------+--------------------------------------------------------------------------------------+
25. 1 row in set (0.00 sec) 26. mysql> show create table t2; 27. +-------+--------------------------------------------------------------------------------------+
28. | Table | Create Table |
29. +-------+--------------------------------------------------------------------------------------+
30. | t2 | CREATE TABLE t2 (
31. id int(11) DEFAULT NULL
32. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
33. +-------+--------------------------------------------------------------------------------------+
34. 1 row in set (0.00 sec) 18.批量插入数据 01. mysql> insert into t1 value (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); 02. Query OK, 10 rows affected (0.00 sec)
03. Records: 10 Duplicates: 0 Warnings: 0 04. mysql> insert into t2 value (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); 05. Query OK, 10 rows affected (0.01 sec)
06. Records: 10 Duplicates: 0 Warnings: 0 07. mysql> insert into t1 select * from t1; 08. Query OK, 10 rows affected (0.00 sec)
09. Records: 10 Duplicates: 0 Warnings: 0 10. mysql> insert into t2 select * from t2; 11. Query OK, 10 rows affected (0.10 sec)
12. Records: 10 Duplicates: 0 Warnings: 0 13. mysql> select count(
) from t1; 14. +----------+
15. | count(
) |
16. +----------+
17. | 20 |
18. +----------+
19. 1 row in set (0.00 sec) 20. mysql> select count() from t2; 21. +----------+
22. | count(
) |
23. +----------+
24. | 20 |
25. +----------+
26. 1 row in set (0.00 sec)sql

3、100 万数据性能测试 1.t1表插入并查询数据(MyISAM引擎) 01. mysql> insert into t1 select * from t1; 02. Query OK, 1310720 rows affected (0.68 sec)
03. Records: 1310720 Duplicates: 0 Warnings: 0 04. mysql> select count() from t1; 05. +----------+
06. | count(
) |
07. +----------+
08. | 2621440 |
09. +----------+
10. 1 row in set (0.00 sec) 2.t2表插入并查询数据(InnoDB引擎) 01. mysql> insert into t2 select * from t2; 02. Query OK, 1310720 rows affected (12.26 sec)
03. Records: 1310720 Duplicates: 0 Warnings: 0 04. mysql> select count() from t2; 05. +----------+
06. | count(
) |
07. +----------+
08. | 2621440 |
09. +----------+
10. 1 row in set (0.79 sec) 3.总结 (1).MyISAM 引擎 插入100多万行数据花费的时间为 0.68 秒。 用select count() from t1 命令查询的时间为 0.00 秒。 (2).InnoDB 引擎 插入100多万行数据花费的时间为 12.26 秒。 用select count() from t1 命令查询的时间为 0.79 秒。vim

4、200 万数据性能测试 1.t1表插入并查询数据(MyISAM引擎) 01. mysql> insert into t1 select * from t1; 02. Query OK, 2621440 rows affected (1.18 sec)
03. Records: 2621440 Duplicates: 0 Warnings: 0 04. mysql> select count() from t1; 05. +----------+
06. | count(
) |
07. +----------+
08. | 5242880 |
09. +----------+
10. 1 row in set (0.00 sec) 2.t2表插入并查询数据(InnoDB引擎) 01. mysql> insert into t2 select * from t2; 02. Query OK, 2621440 rows affected (26.13 sec)
03. Records: 2621440 Duplicates: 0 Warnings: 0 04. mysql> select count() from t2; 05. +----------+
06. | count(
) |
07. +----------+
08. | 5242880 |
09. +----------+
10. 1 row in set (1.59 sec) 3.总结 (1).MyISAM 引擎 插入200多万行数据花费的时间为 1.18 秒。 用select count() from t1 命令查询的时间为 0.00 秒。 (2).InnoDB 引擎 插入200多万行数据花费的时间为 26.13 秒。 用select count() from t1 命令查询的时间为 1.59 秒。app

5、500 万数据性能测试 1.t1表插入并查询数据(MyISAM引擎) 01. mysql> insert into t1 select * from t1; 02. Query OK, 5242880 rows affected (2.27 sec)
03. Records: 5242880 Duplicates: 0 Warnings: 0 04. mysql> select count() from t1; 05. +----------+
06. | count(
) |
07. +----------+
08. | 10485760 |
09. +----------+
10. 1 row in set (0.00 sec) 2.t2表插入并查询数据(InnoDB引擎) 01. mysql> insert into t2 select * from t2; 02. Query OK, 5242880 rows affected (55.33 sec)
03. Records: 5242880 Duplicates: 0 Warnings: 0 04. mysql> select count() from t2; 05. +----------+
06. | count(
) |
07. +----------+
08. | 10485760 |
09. +----------+
10. 1 row in set (4.04 sec) (1).MyISAM 引擎 插入500多万行数据花费的时间为 2.27 秒。 用select count() from t1 命令查询的时间为 0.00 秒。 (2).InnoDB 引擎 插入500多万行数据花费的时间为 55.33 秒。 用select count() from t1 命令查询的时间为 4.04 秒。性能

6、1000 万数据性能测试 1.t1表插入并查询数据(MyISAM引擎) 01. mysql> insert into t1 select * from t1; 02. Query OK, 10485760 rows affected (6.57 sec)
03. Records: 10485760 Duplicates: 0 Warnings: 0 04. mysql> select count() from t1; 05. +----------+
06. | count(
) |
07. +----------+
08. | 20971520 |
09. +----------+
10. 1 row in set (0.09 sec) 2.t2表插入并查询数据(InnoDB引擎) 01. mysql> insert into t2 select * from t2; 02. Query OK, 10485760 rows affected (1 min 50.43 sec)
03. Records: 10485760 Duplicates: 0 Warnings: 0 04. mysql> select count() from t2; 05. +----------+
06. | count(
) |
07. +----------+
08. | 20971520 |
09. +----------+
10. 1 row in set (11.36 sec) (1).MyISAM 引擎 插入1000多万行数据花费的时间为 6.57 秒。 用select count() from t1 命令查询的时间为 0.09 秒。 (2).InnoDB 引擎 插入1000多万行数据花费的时间为 1 min 50.43 秒。 用select count() from t1 命令查询的时间为 11.36 秒。测试

7、总结 MyISAM 引擎 数据(单位/万) 插入数据时间(单位/秒) 查询数据时间(单位/秒) 100 0.68 0.00 200 1.18 0.00 500 2.27 0.00 1000 6.57 0.09ui

InnoDB 引擎 数据(单位/万) 插入数据时间(单位/秒) 查询数据时间(单位/秒) 100 12.26 0.79 200 26.13 1.59 500 55.33 4.04 1000 1 min 50.43 11.36.net

8、MySQL 5.1与MySQL 5.5 MyISAM与InnoDB引擎对比 1.MySQL 5.1 MyISAM 引擎 数据(单位/万) 插入数据时间(单位/秒) 查看数据时间(单位/秒) 100 0.64 0.00 200 1.23 0.00 500 2.35 0.00 1000 8.47 0.07

InnoDB 引擎 数据(单位/万) 插入数据时间(单位/秒) 查看数据时间(单位/秒) 100 13.03 1.20 200 26.32 2.08 500 52.81 6.63 1000 53.02 18.50 2.总结 通过上面的表格结比相信你们对,MySQL 5.1与MySQL 5.5 MyISAM引擎与InnoDB引擎的读写性能有所了解,MySQL 5.5 的InnoDB引擎在1000万行之内的性能有明显提高。整体来讲无论是引擎的读写性能仍是TPS与rw request /s性能,MySQL 5.5的性能都有很大的提高,仍是那句话找个稳定的5.5版本升了吧。最后,但愿你们有所收获吧^_^……

相关文章
相关标签/搜索