MySQL 在 CentOS 6x(不是 5x)上运行非常慢

MySQL 在 CentOS 6x(不是 5x)上运行非常慢

我有两台服务器:一台 VPS 和一台笔记本电脑。我最近重建了它们,MySQL 在笔记本电脑上的运行速度大约慢了 20 倍。

两台服务器都运行 CentOS 5.8,我认为是 MySQL 5.1,而且笔记本电脑运行得很好,所以我认为这不是硬件的问题。

对于 VPS,我的提供商安装了​​ CentOS 6.4,然后我使用 yum 和 CentOS repo 安装了 MySQL 5.1.69。

对于笔记本电脑,我安装了 CentOS 6.4 基本服务器,然后使用 yum 和 CentOS repo 安装了 MySQL 5.1.69。

两个服务器的 my.cnf 是相同的,我已在下面显示。对于这两个服务器,我还在下面包含了SHOW VARIABLES;sysbench 的输出以及文件系统信息和 cpu 信息的输出。我尝试添加skip-name-resolve,但没有帮助。

下面的矩阵显示了SHOW VARIABLES两个服务器的输出,它们是不同的。同样,MySQL 的安装方式相同,所以我不知道为什么会有所不同,但事实确实如此,我认为这可能是笔记本电脑执行 MySQL 速度如此缓慢的原因。

为什么笔记本电脑运行 MySQL 很慢,我该如何解决这个问题?

SHOW VARIABLES两台服务器之间的差异

+---------------------------+-----------------------+-------------------------+
|         Variable          |       Value-VPS       |      Value-Laptop       |
+---------------------------+-----------------------+-------------------------+
| hostname                  | vps.site1.com         | laptop.site2.com        |
| max_binlog_cache_size     | 4294963200            | 18446744073709500000    |
| max_seeks_for_key         | 4294967295            | 18446744073709500000    |
| max_write_lock_count      | 4294967295            | 18446744073709500000    |
| myisam_max_sort_file_size | 2146435072            | 9223372036853720000     |
| myisam_mmap_size          | 4294967295            | 18446744073709500000    |
| plugin_dir                | /usr/lib/mysql/plugin | /usr/lib64/mysql/plugin |
| pseudo_thread_id          | 7568                  | 2                       |
| system_time_zone          | EST                   | PDT                     |
| thread_stack              | 196608                | 262144                  |
| timestamp                 | 1372252112            | 1372252046              |
| version_compile_machine   | i386                  | x86_64                  |
+---------------------------+-----------------------+-------------------------+

两个服务器的 my.cnf

[root@server1 ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

innodb_strict_mode=on
sql_mode=TRADITIONAL
# sql_mode=STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE
character-set-server=utf8
collation-server=utf8_general_ci
log=/var/log/mysqld_all.log

[root@server1 ~]#

VPS 显示变量信息

Same as Laptop shown below but changes per above matrix (removed to allow me to be under the 30000 characters as required by ServerFault)

笔记本电脑显示变量信息

auto_increment_increment    1
auto_increment_offset   1
autocommit  ON
automatic_sp_privileges ON
back_log    50
basedir /usr/
big_tables  OFF
binlog_cache_size   32768
binlog_direct_non_transactional_updates OFF
binlog_format   STATEMENT
bulk_insert_buffer_size 8388608
character_set_client    utf8
character_set_connection    utf8
character_set_database  latin1
character_set_filesystem    binary
character_set_results   utf8
character_set_server    latin1
character_set_system    utf8
character_sets_dir  /usr/share/mysql/charsets/
collation_connection    utf8_general_ci
collation_database  latin1_swedish_ci
collation_server    latin1_swedish_ci
completion_type 0
concurrent_insert   1
connect_timeout 10
datadir /var/lib/mysql/
date_format %Y-%m-%d
datetime_format %Y-%m-%d %H:%i:%s
default_week_format 0
delay_key_write ON
delayed_insert_limit    100
delayed_insert_timeout  300
delayed_queue_size  1000
div_precision_increment 4
engine_condition_pushdown   ON
error_count 0
event_scheduler OFF
expire_logs_days    0
flush   OFF
flush_time  0
foreign_key_checks  ON
ft_boolean_syntax   + -><()~*:""&|
ft_max_word_len 84
ft_min_word_len 4
ft_query_expansion_limit    20
ft_stopword_file    (built-in)
general_log OFF
general_log_file    /var/run/mysqld/mysqld.log
group_concat_max_len    1024
have_community_features YES
have_compress   YES
have_crypt  YES
have_csv    YES
have_dynamic_loading    YES
have_geometry   YES
have_innodb YES
have_ndbcluster NO
have_openssl    DISABLED
have_partitioning   YES
have_query_cache    YES
have_rtree_keys YES
have_ssl    DISABLED
have_symlink    DISABLED
hostname    server1.site2.com
identity    0
ignore_builtin_innodb   OFF
init_connect    
init_file   
init_slave  
innodb_adaptive_hash_index  ON
innodb_additional_mem_pool_size 1048576
innodb_autoextend_increment 8
innodb_autoinc_lock_mode    1
innodb_buffer_pool_size 8388608
innodb_checksums    ON
innodb_commit_concurrency   0
innodb_concurrency_tickets  500
innodb_data_file_path   ibdata1:10M:autoextend
innodb_data_home_dir    
innodb_doublewrite  ON
innodb_fast_shutdown    1
innodb_file_io_threads  4
innodb_file_per_table   OFF
innodb_flush_log_at_trx_commit  1
innodb_flush_method 
innodb_force_recovery   0
innodb_lock_wait_timeout    50
innodb_locks_unsafe_for_binlog  OFF
innodb_log_buffer_size  1048576
innodb_log_file_size    5242880
innodb_log_files_in_group   2
innodb_log_group_home_dir   ./
innodb_max_dirty_pages_pct  90
innodb_max_purge_lag    0
innodb_mirrored_log_groups  1
innodb_open_files   300
innodb_rollback_on_timeout  OFF
innodb_stats_method nulls_equal
innodb_stats_on_metadata    ON
innodb_support_xa   ON
innodb_sync_spin_loops  20
innodb_table_locks  ON
innodb_thread_concurrency   8
innodb_thread_sleep_delay   10000
innodb_use_legacy_cardinality_algorithm ON
insert_id   0
interactive_timeout 28800
join_buffer_size    131072
keep_files_on_create    OFF
key_buffer_size 8384512
key_cache_age_threshold 300
key_cache_block_size    1024
key_cache_division_limit    100
language    /usr/share/mysql/english/
large_files_support ON
large_page_size 0
large_pages OFF
last_insert_id  0
lc_time_names   en_US
license GPL
local_infile    ON
locked_in_memory    OFF
log OFF
log_bin OFF
log_bin_trust_function_creators OFF
log_bin_trust_routine_creators  OFF
log_error   /var/log/mysqld.log
log_output  FILE
log_queries_not_using_indexes   OFF
log_slave_updates   OFF
log_slow_queries    OFF
log_warnings    1
long_query_time 10.000000
low_priority_updates    OFF
lower_case_file_system  OFF
lower_case_table_names  0
max_allowed_packet  1048576
max_binlog_cache_size   18446744073709547520
max_binlog_size 1073741824
max_connect_errors  10
max_connections 151
max_delayed_threads 20
max_error_count 64
max_heap_table_size 16777216
max_insert_delayed_threads  20
max_join_size   18446744073709551615
max_length_for_sort_data    1024
max_long_data_size  1048576
max_prepared_stmt_count 16382
max_relay_log_size  0
max_seeks_for_key   18446744073709551615
max_sort_length 1024
max_sp_recursion_depth  0
max_tmp_tables  32
max_user_connections    0
max_write_lock_count    18446744073709551615
min_examined_row_limit  0
multi_range_count   256
myisam_data_pointer_size    6
myisam_max_sort_file_size   9223372036853727232
myisam_mmap_size    18446744073709551615
myisam_recover_options  OFF
myisam_repair_threads   1
myisam_sort_buffer_size 8388608
myisam_stats_method nulls_unequal
myisam_use_mmap OFF
net_buffer_length   16384
net_read_timeout    30
net_retry_count 10
net_write_timeout   60
new OFF
old OFF
old_alter_table OFF
old_passwords   OFF
open_files_limit    1024
optimizer_prune_level   1
optimizer_search_depth  62
optimizer_switch    index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on
pid_file    /var/run/mysqld/mysqld.pid
plugin_dir  /usr/lib64/mysql/plugin
port    3306
preload_buffer_size 32768
profiling   OFF
profiling_history_size  15
protocol_version    10
pseudo_thread_id    3
query_alloc_block_size  8192
query_cache_limit   1048576
query_cache_min_res_unit    4096
query_cache_size    0
query_cache_type    ON
query_cache_wlock_invalidate    OFF
query_prealloc_size 8192
rand_seed1  
rand_seed2  
range_alloc_block_size  4096
read_buffer_size    131072
read_only   OFF
read_rnd_buffer_size    262144
relay_log   
relay_log_index 
relay_log_info_file relay-log.info
relay_log_purge ON
relay_log_space_limit   0
report_host 
report_password 
report_port 3306
report_user 
rpl_recovery_rank   0
secure_auth OFF
secure_file_priv    
server_id   0
skip_external_locking   ON
skip_name_resolve   OFF
skip_networking OFF
skip_show_database  OFF
slave_compressed_protocol   OFF
slave_exec_mode STRICT
slave_load_tmpdir   /tmp
slave_max_allowed_packet    1073741824
slave_net_timeout   3600
slave_skip_errors   OFF
slave_transaction_retries   10
slow_launch_time    2
slow_query_log  OFF
slow_query_log_file /var/run/mysqld/mysqld-slow.log
socket  /var/lib/mysql/mysql.sock
sort_buffer_size    2097144
sql_auto_is_null    ON
sql_big_selects ON
sql_big_tables  OFF
sql_buffer_result   OFF
sql_log_bin ON
sql_log_off OFF
sql_log_update  ON
sql_low_priority_updates    OFF
sql_max_join_size   18446744073709551615
sql_mode    
sql_notes   ON
sql_quote_show_create   ON
sql_safe_updates    OFF
sql_select_limit    18446744073709551615
sql_slave_skip_counter  
sql_warnings    OFF
ssl_ca  
ssl_capath  
ssl_cert    
ssl_cipher  
ssl_key 
storage_engine  MyISAM
sync_binlog 0
sync_frm    ON
system_time_zone    PDT
table_definition_cache  256
table_lock_wait_timeout 50
table_open_cache    64
table_type  MyISAM
thread_cache_size   0
thread_handling one-thread-per-connection
thread_stack    262144
time_format %H:%i:%s
time_zone   SYSTEM
timed_mutexes   OFF
timestamp   1372254399
tmp_table_size  16777216
tmpdir  /tmp
transaction_alloc_block_size    8192
transaction_prealloc_size   4096
tx_isolation    REPEATABLE-READ
unique_checks   ON
updatable_views_with_limit  YES
version 5.1.69
version_comment Source distribution
version_compile_machine x86_64
version_compile_os  redhat-linux-gnu
wait_timeout    28800
warning_count   0

VPS Sysbench 信息

已删除,以保持在 30000 个字符以下。

笔记本电脑 Sysbench 信息

[root@server1 ~]# cat sysbench.txt
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 8

Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 7 times)
Done.

OLTP test statistics:
    queries performed:
        read:                            634718
        write:                           0
        other:                           90674
        total:                           725392
    transactions:                        45337  (755.56 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 634718 (10577.78 per sec.)
    other operations:                    90674  (1511.11 per sec.)

Test execution summary:
    total time:                          60.0048s
    total number of events:              45337
    total time taken by event execution: 479.4912
    per-request statistics:
         min:                                  2.04ms
         avg:                                 10.58ms
         max:                                 85.56ms
         approx.  95 percentile:              19.70ms

Threads fairness:
    events (avg/stddev):           5667.1250/42.18
    execution time (avg/stddev):   59.9364/0.00

[root@server1 ~]#

VPS 文件信息

[root@vps ~]# df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/simfs   simfs    20971520  16187440   4784080  78% /
none         tmpfs     6224432         4   6224428   1% /dev
none         tmpfs     6224432         0   6224432   0% /dev/shm
[root@vps ~]#

笔记本电脑文件信息

[root@server1 ~]# df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_server1-lv_root
              ext4    72383800   4243964  64462860   7% /
tmpfs        tmpfs      956352         0    956352   0% /dev/shm
/dev/sdb1     ext4      495844     60948    409296  13% /boot
[root@server1 ~]#

VPS CPU 信息

Removed to stay under the 30000 character limit required by ServerFault

笔记本电脑 CPU 信息

[root@server1 ~]# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Core(TM)2 Duo CPU     T7100  @ 1.80GHz
stepping        : 13
cpu MHz         : 800.000
cache size      : 2048 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm ida dts tpr_shadow vnmi flexpriority
bogomips        : 3591.39
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 15
model name      : Intel(R) Core(TM)2 Duo CPU     T7100  @ 1.80GHz
stepping        : 13
cpu MHz         : 800.000
cache size      : 2048 KB
physical id     : 0
siblings        : 2
core id         : 1
cpu cores       : 2
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm ida dts tpr_shadow vnmi flexpriority
bogomips        : 3591.39
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

[root@server1 ~]#

编辑 shakalandy 请求的新信息

[root@localhost ~]# cat /proc/meminfo
MemTotal:        2044804 kB
MemFree:          761464 kB
Buffers:           68868 kB
Cached:           369708 kB
SwapCached:            0 kB
Active:           881080 kB
Inactive:         246016 kB
Active(anon):     688312 kB
Inactive(anon):     4416 kB
Active(file):     192768 kB
Inactive(file):   241600 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       4095992 kB
SwapFree:        4095992 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        688428 kB
Mapped:            65156 kB
Shmem:              4216 kB
Slab:              92428 kB
SReclaimable:      31260 kB
SUnreclaim:        61168 kB
KernelStack:        2392 kB
PageTables:        28356 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     5118392 kB
Committed_AS:    1530212 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      343604 kB
VmallocChunk:   34359372920 kB
HardwareCorrupted:     0 kB
AnonHugePages:    520192 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:        8556 kB
DirectMap2M:     2078720 kB
[root@localhost ~]# ps aux | grep mysql
root      2227  0.0  0.0 108332  1504 ?        S    07:36   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.badobe.com.pid
mysql     2319  0.1 24.5 1470068 501360 ?      Sl   07:36   0:57 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.badobe.com.err --pid-file=/var/lib/mysql/localhost.badobe.com.pid
root      3579  0.0  0.1 201840  3028 pts/0    S+   07:40   0:00 mysql -u root -p
root     13887  0.0  0.1 201840  3036 pts/3    S+   18:08   0:00 mysql -uroot -px xxxxxxxxxx
root     14449  0.0  0.0 103248   840 pts/2    S+   18:16   0:00 grep mysql
[root@localhost ~]# ps aux | grep mysql
root      2227  0.0  0.0 108332  1504 ?        S    07:36   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.badobe.com.pid
mysql     2319  0.1 24.5 1470068 501356 ?      Sl   07:36   0:57 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.badobe.com.err --pid-file=/var/lib/mysql/localhost.badobe.com.pid
root      3579  0.0  0.1 201840  3028 pts/0    S+   07:40   0:00 mysql -u root -p
root     13887  0.0  0.1 201840  3048 pts/3    S+   18:08   0:00 mysql -uroot -px xxxxxxxxxx
root     14470  0.0  0.0 103248   840 pts/2    S+   18:16   0:00 grep mysql
[root@localhost ~]# vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 742172  76376 371064    0    0     6     6   78  202  2  1 97  1  0
 0  0      0 742164  76380 371060    0    0     0    16  191  467  2  1 93  5  0
 0  0      0 742164  76380 371064    0    0     0     0  148  388  2  1 98  0  0
 0  0      0 742164  76380 371064    0    0     0     0  159  418  2  1 98  0  0
 0  0      0 742164  76380 371064    0    0     0     0  145  380  2  1 98  0  0
 0  0      0 742164  76380 371064    0    0     0     0  166  429  2  1 97  0  0
 1  0      0 742164  76380 371064    0    0     0     0  148  373  2  1 98  0  0
 0  0      0 742164  76380 371064    0    0     0     0  149  382  2  1 98  0  0
 0  0      0 742164  76380 371064    0    0     0     0  168  408  2  0 97  0  0
 0  0      0 742164  76380 371064    0    0     0     0  165  394  2  1 98  0  0
 0  0      0 742164  76380 371064    0    0     0     0  159  354  2  1 98  0  0
 0  0      0 742164  76388 371060    0    0     0    16  180  447  2  0 91  6  0
 0  0      0 742164  76388 371064    0    0     0     0  143  344  2  1 98  0  0
 0  1      0 742784  76416 370044    0    0    28   580  360  678  3  1 74 23  0
 1  0      0 744768  76496 367772    0    0    40  1036  437  865  3  1 53 43  0
 0  1      0 747248  76596 365412    0    0    48  1224  561  923  3  2 53 43  0
 0  1      0 749232  76696 363092    0    0    32  1132  512  883  3  2 52 44  0
 0  1      0 751340  76772 361020    0    0    32  1008  472  872  2  1 52 45  0
 0  1      0 753448  76840 358540    0    0    36  1088  512  860  2  1 51 46  0
 0  1      0 755060  76936 357636    0    0    28  1012  481  922  2  2 52 45  0
 0  1      0 755060  77064 357988    0    0    12   896  444  902  2  1 53 45  0
 0  1      0 754688  77148 358448    0    0    16  1096  506 1007  1  1 56 42  0
 0  2      0 754192  77268 358932    0    0    12  1060  481  957  1  2 53 44  0
 0  1      0 753696  77380 359392    0    0    12  1052  512 1025  2  1 55 42  0
 0  1      0 751028  77480 359828    0    0     8   984  423  909  2  2 52 45  0
 0  1      0 750524  77620 360200    0    0     8   788  367  869  1  2 54 44  0
 0  1      0 749904  77700 360664    0    0     8   928  439  924  2  2 55 43  0
 0  1      0 749408  77796 361084    0    0    12   976  468  967  1  1 56 43  0
 0  1      0 748788  77896 361464    0    0    12   992  453  944  1  2 54 43  0
 1  1      0 748416  77992 361996    0    0    12   784  392  868  2  1 52 46  0
 0  1      0 747920  78092 362336    0    0     4   896  382  874  1  1 52 46  0
 0  1      0 745252  78172 362780    0    0    12  1040  444  923  1  1 56 42  0
 0  1      0 744764  78288 363220    0    0     8  1024  448  934  2  1 55 43  0
 0  1      0 744144  78408 363668    0    0     8  1000  461  982  2  1 53 44  0
 0  1      0 743648  78488 364148    0    0     8   872  443  888  2  1 54 43  0
 0  1      0 743152  78548 364468    0    0    16  1020  511  995  2  1 55 43  0
 0  1      0 742656  78632 365024    0    0    12   928  431  913  1  2 53 44  0
 0  1      0 742160  78728 365468    0    0    12   996  470  955  2  2 54 44  0
 1  1      0 739492  78840 365896    0    0     8   988  447  939  1  2 52 46  0
 0  1      0 738872  78996 366352    0    0    12   972  442  928  1  1 55 44  0
 1  1      0 738244  79148 366812    0    0     8   948  549 1126  2  2 54 43  0
 0  1      0 737624  79312 367188    0    0    12   996  456  953  2  2 54 43  0
 0  1      0 736880  79456 367660    0    0    12   960  444  918  1  1 53 46  0
 0  1      0 736260  79584 368124    0    0     8   884  414  921  1  1 54 44  0
 0  1      0 735648  79716 368488    0    0    12   976  450  955  2  1 56 41  0
 0  1      0 733104  79840 368988    0    0    12   932  453  918  1  2 55 43  0
 0  1      0 732608  79996 369356    0    0    16   916  444  889  1  2 54 43  0
 1  1      0 731476  80128 369800    0    0    16   852  514  978  2  2 54 43  0
 0  1      0 731244  80252 370200    0    0     8   904  398  870  2  1 55 43  0
 1  1      0 730624  80384 370612    0    0    12  1032  447  977  1  2 57 41  0
 0  1      0 730004  80524 371096    0    0    12   984  469  941  2  2 52 45  0
 0  1      0 729508  80636 371544    0    0    12   928  438  922  2  1 52 46  0
 0  1      0 728888  80756 371948    0    0    16   972  439  943  2  1 55 43  0
 0  1      0 726468  80900 372272    0    0     8   960  545 1024  2  1 54 43  0
 1  1      0 726344  81024 372272    0    0     8   464  490 1057  1  2 53 44  0
 0  1      0 726096  81148 372276    0    0     4   328  441 1063  2  1 53 45  0
 1  1      0 726096  81256 372292    0    0     0   296  387  975  1  1 53 45  0
 0  1      0 725848  81380 372284    0    0     4   332  425 1034  2  1 54 44  0
 1  1      0 725848  81496 372300    0    0     4   308  386  992  2  1 54 43  0
 0  1      0 725600  81616 372296    0    0     4   328  404 1060  1  1 54 44  0
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  1      0 725600  81732 372296    0    0     4   328  439 1011  1  1 53 44  0
 0  1      0 725476  81848 372308    0    0     0   316  441 1023  2  2 52 46  0
 1  1      0 725352  81972 372300    0    0     4   344  451 1021  1  1 55 43  0
 2  1      0 725228  82088 372320    0    0     0   328  427 1058  1  1 54 44  0
 1  1      0 724980  82220 372300    0    0     4   336  419  999  2  1 54 44  0
 1  1      0 724980  82328 372320    0    0     4   320  430 1019  1  1 54 44  0
 1  1      0 724732  82436 372328    0    0     0   388  363  942  2  1 54 44  0
 1  1      0 724608  82560 372312    0    0     4   308  419  993  1  2 54 44  0
 1  0      0 724360  82684 372320    0    0     0   304  421 1028  2  1 55 42  0
 1  0      0 724360  82684 372388    0    0     0     0  158  416  2  1 98  0  0
 1  1      0 724236  82720 372360    0    0     0  6464  243  855  3  2 84 12  0
 1  0      0 724112  82748 372360    0    0     0  5356  266  895  3  1 84 12  0
 2  1      0 724112  82764 372380    0    0     0  3052  221  511  2  2 93  4  0
 1  0      0 724112  82796 372372    0    0     0  4548  325 1067  2  2 81 16  0
 1  0      0 724112  82816 372368    0    0     0  3240  259  829  3  1 90  6  0
 1  0      0 724112  82836 372380    0    0     0  3260  309  822  3  2 88  8  0
 1  1      0 724112  82876 372364    0    0     0  4680  326  978  3  1 77 19  0
 1  0      0 724112  82884 372380    0    0     0   512  207  508  2  1 95  2  0
 1  0      0 724112  82884 372388    0    0     0     0  138  361  2  1 98  0  0
 1  0      0 724112  82884 372388    0    0     0     0  158  397  2  1 98  0  0
 1  0      0 724112  82884 372388    0    0     0     0  146  395  2  1 98  0  0
 2  0      0 724112  82884 372388    0    0     0     0  160  395  2  1 98  0  0
 1  0      0 724112  82884 372388    0    0     0     0  163  382  1  1 98  0  0
 1  0      0 724112  82884 372388    0    0     0     0  176  422  2  1 98  0  0
 1  0      0 724112  82884 372388    0    0     0     0  134  351  2  1 98  0  0
 0  0      0 724112  82884 372388    0    0     0     0  190  429  2  1 97  0  0
 0  0      0 724104  82884 372392    0    0     0     0  139  358  2  1 98  0  0
 0  0      0 724848  82884 372392    0    0     0     4  211  432  2  1 97  0  0
 1  0      0 724980  82884 372392    0    0     0     0  166  370  2  1 98  0  0
 0  0      0 724980  82884 372392    0    0     0     0  164  397  2  1 98  0  0
^C
[root@localhost ~]#

数据库大小

mysql> SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB", sum( data_free )/ 1024 / 1024 "Free Space in MB" FROM information_schema.TABLES GROUP BY table_schema;
+--------------------+----------------------+------------------+
| Data Base Name     | Data Base Size in MB | Free Space in MB |
+--------------------+----------------------+------------------+
| bidjunction        |           4.68750000 |       0.00000000 |
| information_schema |           0.00976563 |       0.00000000 |
| mysql              |           0.63899899 |       0.00105286 |
+--------------------+----------------------+------------------+
3 rows in set (0.01 sec)

mysql>

查询前

mysql> SHOW SESSION STATUS like '%Tmp%';
+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 0     |
| Created_tmp_files       | 6     |
| Created_tmp_tables      | 0     |
+-------------------------+-------+
3 rows in set (0.00 sec)

mysql>

查询后

mysql> SHOW SESSION STATUS like '%Tmp%';
+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 0     |
| Created_tmp_files       | 6     |
| Created_tmp_tables      | 2     |
+-------------------------+-------+
3 rows in set (0.00 sec)

mysql>

答案1

CentOS 6.x 使用 ext4。如果您的数据目录在 ext4 上,请设置 barrier=0 选项。

这里

干杯

答案2

您可以通过购买较新的笔记本电脑来“解决”该问题。

首先,您的笔记本电脑使用的是已有六年历史的 CPU(并且处于省电模式!),它甚至不是真正为服务器工作负载而设计的。

第二……不,这才是“问题”的根源。

答案3

虽然您发布了您的配置,但缺少很多其他信息。

  1. 你有多少内存?
  2. MySQL 在你的笔记本电脑上占用了多少内存?(ps aux)
  3. 你测试的数据库有多大?
  4. 您的数据库是否使用 MyIsam 或 InnoDB 表引擎?
  5. 你能给它增加一些工作量并记录输出吗vmstat 1几分钟?

答案4

服务器/vps 可能配有带内存电池备份的缓存 RAID 卡,因此写入操作在达到较慢的磁盘 iops 之前会直接在 RAID 控制器内存中确认,而您的笔记本电脑则不会,除非它配有 SSD。这会对性能产生巨大影响。

在您的设置文件中:innodb_flush_log_at_trx_commit 1

我建议您尝试将 innodb_flush_log_at_trx_commit 变量放宽为 0 或尝试使用 my-large.cnf 您的 MySQL devel 服务器不再完全符合 ACID 标准但它的运行速度会快得多。

相关内容