2017-03-17 65 views
-1

我有一个ec2 t2.micro实例,内存为1 GB。调整mysql数据库的性能

我的数据库包含一个记录大约120万的单个表。

我应该如何调整我的数据库?

这是结果运行mysqltuner 后,我得到是的,我已经调整建议从下面给出的变量,但仍然没有改变

--------日志文件的建议------ ---------------------------------------- ---------- ----------

[--] Log file: /var/log/mysql/error.log(31K) 
[OK] Log file /var/log/mysql/error.log exists 
[OK] Log file /var/log/mysql/error.log is readable. 
[OK] Log file /var/log/mysql/error.log is not empty 
[OK] Log file /var/log/mysql/error.log is smaller than 32 Mb 
[!!] /var/log/mysql/error.log contains 21 warning(s). 
[!!] /var/log/mysql/error.log contains 15 error(s). 
[--] 4 start(s) detected in /var/log/mysql/error.log 
[--] 1) 2017-03-17T07:41:04.336711Z 0 [Note] /usr/sbin/mysqld: ready for connections. 
[--] 2) 2017-03-17T07:26:38.914453Z 0 [Note] /usr/sbin/mysqld: ready for connect             ions. 
[--] 3) 2017-03-17T06:44:00.306760Z 0 [Note] /usr/sbin/mysqld: ready for connections. 
[--] 4) 2017-03-17T06:42:45.581096Z 0 [Note] /usr/sbin/mysqld: ready for connections. 
[--] 3 shutdown(s) detected in /var/log/mysql/error.log 
[--] 1) 2017-03-17T07:40:20.754987Z 0 [Note] /usr/sbin/mysqld: Shutdown complete 
[--] 2) 2017-03-17T07:26:37.241863Z 0 [Note] /usr/sbin/mysqld: Shutdown complete 
[--] 3) 2017-03-17T06:43:56.024176Z 0 [Note] /usr/sbin/mysqld: Shutdown complete 

--------性能指标----------------------- ------------------------------------------------

[--] Up for: 1h 8m 38s (31K q [7.602 qps], 11K conn, TX: 16M, RX: 6M) 
[--] Reads/Writes: 99%/1% 
[--] Binary logging is disabled 
[--] Physical Memory  : 990.7M 
[--] Max MySQL memory : 386.4M 
[--] Other process memory: 448.8M 
[--] Total buffers: 226.0M global + 1.1M per thread (151 max threads) 
[--] P_S Max memory usage: 72B 
[--] Galera GCache Max memory usage: 0B 
[OK] Maximum reached memory usage: 264.3M (26.67% of installed RAM) 
[OK] Maximum possible memory usage: 386.4M (39.01% of installed RAM) 
[OK] Overall possible memory usage with other process is compatible with memory available 
[OK] Slow queries: 0% (0/31K) 
[OK] Highest usage of available connections: 23% (36/151) 
[OK] Aborted connections: 0.02% (2/11501) 
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance 
[!!] Query cache may be disabled by default due to mutex contention. 
[!!] Query cache efficiency: 14.3% (2K cached/19K selects) 
[OK] Query cache prunes per day: 0 
[OK] Sorts requiring temporary tables: 0% (0 temp sorts/18K sorts) 
[OK] No joins without indexes 
[!!] Temporary tables created on disk: 49% (7K on disk/14K total) 
[OK] Thread cache hit rate: 99% (78 created/11K connections) 
[OK] Table cache hit rate: 59% (129 open/217 opened) 
[OK] Open file limit used: 0% (6/1K) 
[OK] Table locks acquired immediately: 100% (102 immediate/102 locks) 

-------- MyISAM指标-------------------------------------- --------------------------------------

[!!] Key buffer used: 18.2% (3M used/16M cache) 
[OK] Key buffer size/total MyISAM indexes: 16.0M/52.0K 
[!!] Read Key buffer hit rate: 50.0% (6 cached/3 reads) 

----- --- InnoDB指标--------------------------------------------- -------------------------------

[--] InnoDB is enabled. 
[--] InnoDB Thread Concurrency: 0 
[OK] InnoDB File per table is activated 
[!!] InnoDB buffer pool/data size: 128.0M/603.0M 
[!!] Ratio InnoDB log file size/InnoDB Buffer pool size (75 %): 48.0M * 2/128.0M should be equal 25% 
[OK] InnoDB buffer pool instances: 1 
[--] Number of InnoDB Buffer Pool Chunk : 1 for 1 Buffer Pool Instance(s) 
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances 
[OK] InnoDB Read buffer efficiency: 95.01% (92607770 hits/ 97474927 total) 
[!!] InnoDB Write Log efficiency: 229.41% (39 hits/ 17 total) 
[OK] InnoDB log waits: 0.00% (0 waits/56 writes) 

--------建议--- -------------------------------------------------- ----------------------

General recommendations: 

Control warning line(s) into /var/log/mysql/error.log file 
Control error line(s) into /var/log/mysql/error.log file 
MySQL started within last 24 hours - recommendations may be inaccurate 
Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1 

When making adjustments, make tmp_table_size/max_heap_table_size equal 
Reduce your SELECT DISTINCT queries which have no LIMIT clause 

Variables to adjust: 

query_cache_type (=0) 
query_cache_limit (> 1M, or use smaller result sets) 
tmp_table_size (> 16M) 
max_heap_table_size (> 16M) 
innodb_buffer_pool_size (>= 603M) if possible. 
innodb_log_file_size should be equals to 1/4 of buffer pool size (=32M) if possible. 

表结构

Table Structure

+0

你能告诉我们表格结构吗?无论多大的数据库都不应该很难处理 – Peter

+0

调整数据库设置与sw开发无关,DBA有更好的位置来回答这些问题。 – Shadow

+0

我添加了截图@Peter – Azhar

回答

1

如果“用户正在寻找一个特定filename,那么你可以做以下显著提高性能:

提供一个复选框,说他是否是给初名称或名称的中间。然后相应地建立LIKE '$in%'LIKE '%$in%'。并有INDEX(filename)

如果用户可以忽略文件名,您可能需要INDEX(filesize)或他可能搜索的其他列。这也有助于WHERE filename LIKE '%xyz%' AND filesize > 1000,因为LIKE中的前导通配符不能被有效地搜索。

“通过OFFSET分页”是另一个我反驳的问题。