【mysql】性能调优实验

mysql版本:mysql  Ver 14.12 Distrib 5.0.37, for pc-linux-gnu (i686) using readline 5.0

1、未调优的情况

my.cnf的主要配置参数:

[mysqld]

skip-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M


[mysql]
no-auto-rehash


[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

 

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

 

[mysqlhotcopy]
interactive-timeout

建两张表:

 

CREATE TABLE `T_TRANS_INFO_INNODB` (
  `MID` varchar(32) NOT NULL DEFAULT '',
  `SCHOOLNO` char(5) NOT NULL DEFAULT '',
  `MOBILENO` char(12) NOT NULL DEFAULT '' COMMENT '手机号',
  `CARDNO` char(32) NOT NULL DEFAULT '' COMMENT '卡号',
  `TRANSTYPE` char(2) NOT NULL DEFAULT '' COMMENT '交易类型',
  `AMOUNT` int(11) NOT NULL DEFAULT 0 COMMENT '金额',
  `TRANSTIME` char(20) NOT NULL DEFAULT '' COMMENT '交易时间,格式yyyy-MMdd HH:mm:ss',
  `INTIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入库时间',
  `MODTIME` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '修改时间',
  `RESERVED1` varchar(32) NOT NULL DEFAULT '' COMMENT '扩展字段1',
  `RESERVED2` varchar(32) NOT NULL DEFAULT '' COMMENT '扩展字段2',
  `ORGANIZATIONNO` char(4) NOT NULL DEFAULT '' COMMENT '组织机构编号',
  `TRANSDATE` int NOT NULL DEFAULT 0 COMMENT '交易日期',
  PRIMARY KEY (`MID`,`SCHOOLNO`,`TRANSDATE`),
  KEY `IDX_AMOUNT` (`AMOUNT`),
  KEY `IDX_TRANSTYPE` (`TRANSTYPE`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk;

 


CREATE TABLE `T_TRANS_INFO_MyISAM` (
  `MID` varchar(32) NOT NULL DEFAULT '',
  `SCHOOLNO` char(5) NOT NULL DEFAULT '',
  `MOBILENO` char(12) NOT NULL DEFAULT '' COMMENT '手机号',
  `CARDNO` char(32) NOT NULL DEFAULT '' COMMENT '卡号',
  `TRANSTYPE` char(2) NOT NULL DEFAULT '' COMMENT '交易类型',
  `AMOUNT` int(11) NOT NULL DEFAULT 0 COMMENT '金额',
  `TRANSTIME` char(20) NOT NULL DEFAULT '' COMMENT '交易时间,格式yyyy-MMdd HH:mm:ss',
  `INTIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入库时间',
  `MODTIME` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '修改时间',
  `RESERVED1` varchar(32) NOT NULL DEFAULT '' COMMENT '扩展字段1',
  `RESERVED2` varchar(32) NOT NULL DEFAULT '' COMMENT '扩展字段2',
  `ORGANIZATIONNO` char(4) NOT NULL DEFAULT '' COMMENT '组织机构编号',
  `TRANSDATE` int NOT NULL DEFAULT 0 COMMENT '交易日期',
  PRIMARY KEY (`MID`,`SCHOOLNO`,`TRANSDATE`),
  KEY `IDX_AMOUNT` (`AMOUNT`),
  KEY `IDX_TRANSTYPE` (`TRANSTYPE`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;

 

 

未调优的情况:


mysql> source /home/dbuser/liying/CARD.T_TRANS_INFO.txt.test.innodb
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 7201 rows affected (0.51 sec)
Records: 7201  Duplicates: 0  Warnings: 0

Query OK, 7218 rows affected (0.58 sec)
Records: 7218  Duplicates: 0  Warnings: 0

Query OK, 7230 rows affected (0.38 sec)
Records: 7230  Duplicates: 0  Warnings: 0

Query OK, 7227 rows affected (0.50 sec)
Records: 7227  Duplicates: 0  Warnings: 0

Query OK, 7191 rows affected (0.49 sec)
Records: 7191  Duplicates: 0  Warnings: 0

Query OK, 7209 rows affected (0.45 sec)
Records: 7209  Duplicates: 0  Warnings: 0

Query OK, 7224 rows affected (0.57 sec)
Records: 7224  Duplicates: 0  Warnings: 0

mysql> source /home/dbuser/liying/CARD.T_TRANS_INFO.txt.test.myisam
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 7201 rows affected (0.34 sec)
Records: 7201  Duplicates: 0  Warnings: 0

Query OK, 7218 rows affected (0.36 sec)
Records: 7218  Duplicates: 0  Warnings: 0

Query OK, 7230 rows affected (0.37 sec)
Records: 7230  Duplicates: 0  Warnings: 0

Query OK, 7227 rows affected (0.38 sec)
Records: 7227  Duplicates: 0  Warnings: 0

Query OK, 7191 rows affected (0.38 sec)
Records: 7191  Duplicates: 0  Warnings: 0

Query OK, 7209 rows affected (0.40 sec)
Records: 7209  Duplicates: 0  Warnings: 0

Query OK, 7224 rows affected (0.39 sec)
Records: 7224  Duplicates: 0  Warnings: 0

可以看出,对于存储效率,Myisam比InnoDB要高些。

 

 

mysql> select count(*) from t_trans_info_innodb;
+----------+
| count(*) |
+----------+
|   559004 |
+----------+
1 row in set (0.27 sec)

mysql> select count(*) from t_trans_info_myisam;
+----------+
| count(*) |
+----------+
|   559004 |
+----------+
1 row in set (0.00 sec)

 

2、通过修改配置参数文件my.cnf进行调优

 

my.cnf参数优化:

 

[mysqld]
default-character-set=gbk
port            = 3306
socket          = /var/lib/mysql/mysql.sock
skip-locking
key_buffer = 256M
max_allowed_packet = 1M
table_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

lower_case_table_names=1
innodb_data_home_dir = /var/lib/mysql/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql/
innodb_log_arch_dir = /var/lib/mysql/
innodb_buffer_pool_size = 256M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

 

[myisamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

 

[mysqlhotcopy]
interactive-timeout

 

 

 

 

调优后情况:

mysql> source /home/dbuser/liying/CARD.T_TRANS_INFO.txt.test.innodb
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 7201 rows affected (0.33 sec)
Records: 7201  Duplicates: 0  Warnings: 0

Query OK, 7218 rows affected (0.35 sec)
Records: 7218  Duplicates: 0  Warnings: 0

Query OK, 7230 rows affected (0.37 sec)
Records: 7230  Duplicates: 0  Warnings: 0

Query OK, 7227 rows affected (0.37 sec)
Records: 7227  Duplicates: 0  Warnings: 0

Query OK, 7191 rows affected (0.38 sec)
Records: 7191  Duplicates: 0  Warnings: 0

Query OK, 7209 rows affected (0.40 sec)
Records: 7209  Duplicates: 0  Warnings: 0

Query OK, 7224 rows affected (0.38 sec)
Records: 7224  Duplicates: 0  Warnings: 0

mysql> source /home/dbuser/liying/CARD.T_TRANS_INFO.txt.test.myisam
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 7201 rows affected (0.33 sec)
Records: 7201  Duplicates: 0  Warnings: 0

Query OK, 7218 rows affected (0.36 sec)
Records: 7218  Duplicates: 0  Warnings: 0

Query OK, 7230 rows affected (0.37 sec)
Records: 7230  Duplicates: 0  Warnings: 0

Query OK, 7227 rows affected (0.37 sec)
Records: 7227  Duplicates: 0  Warnings: 0

Query OK, 7191 rows affected (0.38 sec)
Records: 7191  Duplicates: 0  Warnings: 0

Query OK, 7209 rows affected (0.39 sec)
Records: 7209  Duplicates: 0  Warnings: 0

Query OK, 7224 rows affected (0.39 sec)
Records: 7224  Duplicates: 0  Warnings: 0

 

可见调优后,innodb存储引擎的效率提高比较大

 

 

 

 

 

 

 

你可能感兴趣的:(mysql,null,query,buffer,Warnings,Duplicates)