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版本升了吧。最後,但願你們有所收穫吧^_^……

相關文章
相關標籤/搜索