MySQL 최적화

MySQL 최적화

내 웹서버는 전용 호스트를 사용합니다.

Intel(R) Xeon(R) CPU E5620 8core
12Gram
Centos32bit/Driectadmin
DISK SAS 80G
Php-cgi

이 호스트는 하나의 웹사이트를 운영하고 있습니다.

Use wordpress 2.92(+plugin cache...)
Database size 600MB
only 100online

내 웹사이트가 매우 느리게 실행되고 있습니다. my.cnf를 구성할 수 있도록 도와주세요.

    [mysqld]
user=mysql
key_buffer=128M
set-variable = max_connections=1000
socket          = /var/lib/mysql/mysql.sock
key_buffer =32M
table_cache = 1024
open_files_limit = 16344
join_buffer_size = 8M
read_buffer_size = 8M
sort_buffer_size = 8M
tmp_table_size=512M
read_rnd_buffer_size=8M
max_heap_table_size=256M
#myisam_sort_buffer_size=256M
thread_cache_size=8
thread_cache=32
query_cache_type=1
query_cache_limit=1024M
query_cache_size=1024M
thread_concurrency = 16
wait_timeout = 10
connect_timeout = 10
interactive_timeout = 10
long_query_time=1
log-slow-queries = /var/log/mysqlslowqueries.log
max_allowed_packet=32M
skip-innodb
[myisamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

[isamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M

그리고 MySQLTuner

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.47-log
[!!] Switch to 64-bit OS - MySQL cannot currently use all of your RAM

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated -InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 471M (Tables: 30)
[!!] Total fragmented tables: 2

-------- Performance Metrics -------------------------------------------------
[--] Up for: 1d 6h 39m 2s (6M q [57.776 qps], 60K conn, TX: 999M, RX: 2B)
[--] Reads / Writes: 93% / 7%
[--] Total buffers: 1.3G global + 32.2M per thread (1000 max threads)
[!!] Allocating > 2GB RAM on 32-bit systems can cause system instability
[!!] Maximum possible memory usage: 32.7G (275% of installed RAM)
[OK] Slow queries: 0% (10K/6M)
[OK] Highest usage of available connections: 5% (52/1000)
[OK] Key buffer size / total MyISAM indexes: 32.0M/65.5M
[OK] Key buffer hit rate: 100.0% (938M cached / 108K reads)
[OK] Query cache efficiency: 51.4% (3M cached / 5M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (929 temp sorts / 2M sorts)
[!!] Temporary tables created on disk: 49% (2M on disk / 4M total)
[OK] Thread cache hit rate: 99% (580 created / 60K connections)
[OK] Table cache hit rate: 97% (281 open / 288 opened)
[OK] Open file limit used: 1% (319/16K)
[OK] Table locks acquired immediately: 99% (7M immediate / 7M locks)

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Temporary table size is already large - reduce result set size
    Reduce your SELECT DISTINCT queries without LIMIT clauses

mysqld를 실행할 수 없습니다

[root@server ~]#
[root@server ~]# mysqld
100607 18:21:17 [Warning] mysqld: Option '--set-variable' is deprecated. Use --
100607 18:21:17 [Warning] '--log_slow_queries' is deprecated and will be remove
100607 18:21:17 [Note] Plugin 'FEDERATED' is disabled.
100607 18:21:17 [Note] Plugin 'InnoDB' is disabled.
mysqld: File '/var/log/mysqlslowqueries.log' not found (Errcode: 13)
100607 18:21:17 [ERROR] Could not use /var/log/mysqlslowqueries.log for logging                                          urn it on again: fix the cause, shutdown the MySQL server and restart it.
100607 18:21:17 [ERROR] Can't start server: Bind on TCP/IP port: Address alread
100607 18:21:17 [ERROR] Do you already have another mysqld server running on po
100607 18:21:17 [ERROR] Aborting

100607 18:21:17 [Note] mysqld: Shutdown complete

그리고 위에서부터 출력

[루트@서버 ~]#맨 위

top - 18:45:03 up 3 days,  4:40,  1 user,  load average: 1.80, 1.42, 1.40
Tasks: 266 total,   1 running, 265 sleeping,   0 stopped,   0 zombie
Cpu(s):  4.6%us,  2.5%sy,  0.0%ni, 92.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  12462096k total,  2741388k used,  9720708k free,   599584k buffers
Swap:  8385920k total,        0k used,  8385920k free,  1612488k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 7487 mysql     15   0 1138m 241m 3572 S 98.7  2.0 811:12.72 mysqld
 1508 admin     16   0  166m  43m  21m S  0.3  0.4   0:00.80 php-cgi
 2019 apache    15   0  9264 3268 1444 S  0.3  0.0   0:00.06 httpd
 2089 root      15   0  2336 1132  800 R  0.3  0.0   0:00.15 top
32137 admin     15   0  173m  51m  22m S  0.3  0.4   0:02.11 php-cgi
    1 root      15   0  2072  580  504 S  0.0  0.0   0:02.42 init
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.06 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
    5 root      RT  -5     0    0    0 S  0.0  0.0   0:00.03 migration/1
    6 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/1
    7 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/1
    8 root      RT  -5     0    0    0 S  0.0  0.0   0:00.18 migration/2
    9 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/2
   10 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/2
   11 root      RT  -5     0    0    0 S  0.0  0.0   0:00.02 migration/3
   12 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/3
   13 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/3
   14 root      RT  -5     0    0    0 S  0.0  0.0   0:00.01 migration/4
   15 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/4
   16 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/4
   17 root      RT  -5     0    0    0 S  0.0  0.0   0:00.01 migration/5
   18 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/5
   19 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/5
   20 root      RT  -5     0    0    0 S  0.0  0.0   0:00.01 migration/6
   21 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/6
   22 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/6
   23 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/7
   24 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/7
   25 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/7
   26 root      RT  -5     0    0    0 S  0.0  0.0   0:00.05 migration/8
   27 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/8
   28 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/8
   29 root      RT  -5     0    0    0 S  0.0  0.0   0:00.05 migration/9

답변1

어디서부터 시작해야 할지 모르겠다면, 일단 시작해보세요MySQL튜너.

방금다운로드그리고 펄 스크립트를 실행해 보세요.

mysql 관리자의 사용자 이름과 비밀번호를 요청한 다음 일부 일반 통계, 스토리지 통계, 성능 지표를 나열한 후 최종적으로 권장 사항 목록을 제공합니다.

서버 인스턴스의 초기 검토 시간이 절약됩니다.

문제를 해결한 후에는 실제로 실행한 후 설정을 변경해야 하는지 확인하기 위해 일주일 동안(데이터베이스 사용량에 따라 덜 자주/더 오랫동안) 스크립트를 매 시간마다 실행하는 것이 좋습니다.

또한 살펴보십시오.이와 같은 자원.

MySQL 인스턴스가 정상임을 알게 되면 애플리케이션 코드에서 특정 쿼리를 최적화해야 합니다. 느린 쿼리 로그(아무것도 있으면)를 확인하고 다음과 같은 프로파일러를 사용하여 최악의 위반자를 식별할 수 있습니다.XDebug.

답변2

첫 번째 문제는 32비트 OS에서 실행되고 있다는 것입니다. 귀하는 12G의 Ram을 가지고 있으며(당신의 게시물을 올바르게 읽었다면) 32비트를 실행하고 있기 때문에 Mysql이 그렇게 많이 사용하는 것을 결코 볼 수 없을 것입니다. Centos를 64비트 OS로 업그레이드한 후 Centos에서 제공하는 my.large.cnf 파일을 사용하세요. 그러면 훨씬 더 나은 방향으로 나아갈 수 있을 것입니다. 여전히 문제가 있는 경우 주로 읽기, 쓰기 모두인지 등을 평가해야 합니다. 그러면 Innodb나 MYISAM을 사용해야 한다는 것을 알 수 있습니다. Innodb는 많은 업데이트/쓰기 및 읽기에 적합할 것입니다. 모든 것이 대부분 읽기인 경우 MyISAM이 좋은 선택입니다. 키 캐시 등을 파악하는 데 도움이 되도록 이 정보도 알아야 합니다. 하지만 가장 먼저 해야 할 일은 OS가 해당 RAM을 모두 사용하도록 하는 것입니다.

답변3

show status
show variables
show processlist

php-cgi를 사용하고 있습니까? fcgid 또는 fastcgi?

답변4

mysql 내부에서 실행 중인 MySQL 프로세스를 살펴보셨나요? (예: mytop을 통해?)

MySQLd 프로세스의 높은 CPU 로드로 인해 소름이 돋습니다...

관련 정보