编辑mysql配置文件,查看常用的核心配置项[mysqld]:

[root@centos6 ~]# vim /etc/my.cnf

……

# The MySQL server

[mysqld]

port                                = 3306

socket                             = /tmp/mysql.sock

skip-locking

key_buffer_size               = 256M

max_allowed_packet       = 1M

table_open_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

……

参数说明:

port 端口3306

socket 监听的socket

skip_locking 过滤掉锁

key_buffer_size 索引块的缓冲区大小

max_allowed_packet 用于MySQL的web管理工具phpmyadmin导入包的情况

table_open_cache 所有线程打开表的数量

sort_buffer_size 一个线程用于排序的缓冲区大小

read_buffer_size 读缓冲区大小

read_rnd_buffer_size 随机读缓冲区大小

myisam_sort_buffer_size 用于myisam引擎的排序缓冲区的大小

thread_cache_size 缓存可重用线程数,跟内存有关(1G=8,2G=16,4G以上64)

query_cache_size 查询的缓存大小

thread_concurrency 最大并发线程数,和cpu核数有关系(逻辑CPU数的2倍)

interactive_timeout 交互超时时间

wait_timeout 等待超时时间,自动断开连接,依赖于interactive_timeout

long_query_time 慢查询时间,超过这个时间就要记录日志

log_slow_queries 慢查询日志路径,依赖于long_query_time

mysql调优参考帖子:http://ask.apelearn.com/question/5758

登录mysql:

[root@centos6 ~]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.1.49 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

查看所有参数:

mysql> show variables;

+------------------------ -------+----------------+

| Variable_name                        | Value              |

+--------------------------------+----------------+

| auto_increment_increment     | 1                      |

| auto_increment_offset            | 1                      |

……

查看某个参数的值

mysql> show status like 'key_read%';

+-------------------+-------+

| Variable_name     | Value  |

+-------------------+-------+

| Key_read_requests | 101    |

| Key_reads             | 9        |

+-------------------+-------+

2 rows in set (0.00 sec)

配置使用innodb引擎只需打开MySQL配置文件中的相关内容即可:

[root@centos6 ~]# vim /etc/my.cnf

……

# Uncomment the following if you are using InnoDB tables

#innodb_data_home_dir = /usr/local/mysql/data/

#innodb_data_file_path = ibdata1:10M:autoextend

#innodb_log_group_home_dir = /usr/local/mysql/data/

# You can set .._buffer_pool_size up to 50 - 80 %

# of RAM but beware of setting memory usage too high

#innodb_buffer_pool_size = 256M

#innodb_additional_mem_pool_size = 20M

# Set .._log_file_size to 25 % of buffer pool size

#innodb_log_file_size = 64M

#innodb_log_buffer_size = 8M

#innodb_flush_log_at_trx_commit = 1

#innodb_lock_wait_timeout = 50

……

配置使用二进制日志只需打开我们一开始就注释掉的相关内容即可:

……

# Replication Master Server (default)

# binary logging is required for replication

#log-bin=mysql-bin

# binary logging format - mixed recommended

#binlog_format=mixed

# required unique id between 1 and 2^32 - 1

# defaults to 1 if master-host is not set

# but will not function as a master if omitted

#server-id      = 1

……