|
==配置原则==
===默认引擎:Innodb===
default-storage-engine = innodb
===自增长空间为2G===
ibdata:2048M:autoextend
===默认使用单独文件方式存放数据库的表===
innodb_file_per_table
===默认打开log-bin===
log-bin /home/mysql_logs/mysql-bin
===默认字体:UTF-8===
[mysqld]
character-set-server = utf8
===默认数据库文件存放位置:/home/mysql_data/===
innodb_log_group_home_dir = /home/mysql_data/
innodb_data_home_dir /home/mysql_data/
innodb_data_file_path=ibdata:2048M:autoextend
===默认数据库日记存放位置:/home/mysql_log/===
innodb_log_group_home_dir /home/mysql_log/
===InnoDB日记Buffer===
innodb_log_buffer_size:100M
===在每个事务提交时,日志缓冲被写到日志文件,对日志文件做到磁盘操作的刷新===
innodb_flush_logs_at_trx_commit=1
innodb_lock_wait_timeout = 50
===默认内存大小===
innodb_buffer_pool_size
物理内存=<5G:1/2物理内存内存
5G<物理内存<=8G:2/3物理内存内存
8G<物理内存<=32G:3/4物理内存内存
物理内存>32G:4/5物理内存内存
===innodb_flush_method: 设置InnoDB同步IO的方式===
Default – 使用fsync()。
O_SYNC 以sync模式打开文件,通常比较慢。
O_DIRECT,在Linux上使用Direct IO。可以显著提高速度,特别是在RAID系统上。避免额外的数据复制和double buffering(mysql buffering 和OS buffering)。
===innodb_thread_concurrency:InnoDB kernel最大的线程数===
设置为(num_disks+num_cpus)*2。
===解决mysql不能通过主机名远端连接的问题===
skip-name-resolve
===打开慢查询日记===
long_query_time = 1
slow-query-log-file = /home/mysql_log/log-slow.log
===允许最大的包:1MB===
max_allowed_packet = 8M
===每个连接独立使用的内存===
sort_buffer_size = 4M
read_buffer_size = 2M
===关闭DNS反解===
skip-name-resolve = ON
===默认开启federated引擎===
federated
==库/表命名原则==
*库名:
1、单一库:使用项目名称,e.g. bbs.dalegames.com项目,库名即:bbs_dalegames_com; esales.dalegames.com项目,库名即:esales_dalegames_com;
2、多库,使用项目名称前缀+“_dalegames_com_+“主库/子库两位数的序列号””方式, e.g. '''member.dalegames.com'''项目'''用户库''',主库名即:member_dalegames_com_user_main 、member_dalegames_com_user_sub01 、member_dalegames_com_user_sub02 ......;
*表名:
1、单一库:使用库名前缀+用途,e.g.bbs.dalegames_com项目的用户表(User),表名即:bbs_User; esales.dalegames.com项目是的用户表(User),表名即:esales_User;
2、多库:使用项目名称前缀+用途,e.g. member.dalegames.com项目中的用户表(User),表名即:member_User;
==MySQL 2G以下服务器==
<pre>
db# mkdir -p /home/mysql_data //创建MySQL数据存储目录
db# mkdir -p /home/mysql_logs //创建MySQL日记目录
db# chown mysql.mysql /home/mysql_data/ -R //创建MySQL数据存储目录
db# chown mysql.mysql /home/mysql_logs/ -R //创建MySQL日记目录
db# chown mysql.mysql /var/lib/mysql/performance_schema/ -R
db# mysql_install_db //MySQL 5.5用的是innodb plugin,权限表不结构发生了变化,要使用innodb引擎,需要先使用mysql-install-db 命令生成权限表.
db# chown mysql.mysql /home/mysql_logs/ -R //重新改一下属主;
命令:
mkdir -p /home/mysql_data
mkdir -p /home/mysql_logs
chown mysql.mysql /home/mysql_data/ -R
chown mysql.mysql /home/mysql_logs/ -R
chown mysql.mysql /var/lib/mysql/performance_schema/ -R
mysql_install_db
chown mysql.mysql /home/mysql_logs/ -R
/etc/my.cnf==============================================================
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
max_allowed_packet = 8M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
thread_cache_size = 8
#query_cache_size= 16M //如果我们使用了MemCached,这个就可以关闭
thread_concurrency = 8
server-id = 1
log-bin = /home/mysql_logs/mysql-bin
max_binlog_size=100M
#expire_logs_days=5
#sync_binlog=1
binlog_cache_size=8M
binlog_format = mixed
replicate-ignore-db = mysql
default-storage-engine = innodb
innodb_file_per_table
innodb_data_home_dir = /home/mysql_data/
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_log_group_home_dir = /home/mysql_logs/
innodb_buffer_pool_size = 512M
innodb_additional_mem_pool_size = 128M // innodb_buffer_pool_size的25%即可
innodb_log_file_size = 512M // 这个不可以超过512M
innodb_log_buffer_size = 100M
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
innodb_lock_wait_timeout = 50
character-set-server = utf8
skip-name-resolve
long_query_time = 1
slow-query-log-file = /home/mysql_logs/log-slow.log
federated
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[mysqlhotcopy]
interactive-timeout
</pre>
==MySQL 4G服务器==
<pre>
db# mkdir -p /home/mysql_data //创建MySQL数据存储目录
db# mkdir -p /home/mysql_logs //创建MySQL日记目录
db# chown mysql.mysql /home/mysql_data/ -R //创建MySQL数据存储目录
db# chown mysql.mysql /home/mysql_logs/ -R //创建MySQL日记目录
db# chown mysql.mysql /var/lib/mysql/performance_schema/ -R
db# mysql_install_db //MySQL 5.5用的是innodb plugin,权限表不结构发生了变化,要使用innodb引擎,需要先使用mysql-install-db 命令生成权限表.
db# chown mysql.mysql /home/mysql_logs/ -R //重新改一下属主;
/etc/my.cnf==============================================================
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
max_allowed_packet = 8M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
thread_cache_size = 8
#query_cache_size= 16M //如果我们使用了MemCached,这个就可以关闭
thread_concurrency = 8
server-id = 1
log-bin = /home/mysql_logs/mysql-bin
max_binlog_size=100M
#expire_logs_days=5
#sync_binlog=1
binlog_cache_size=8M
binlog_format = mixed
replicate-ignore-db = mysql
default-storage-engine = innodb
innodb_file_per_table
innodb_data_home_dir = /home/mysql_data/
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_log_group_home_dir = /home/mysql_logs/
innodb_buffer_pool_size = 2G
innodb_additional_mem_pool_size = 512M // innodb_buffer_pool_size的25%即可
innodb_log_file_size = 512M // 这个不可以超过512M
innodb_log_buffer_size = 100M
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
innodb_lock_wait_timeout = 50
character-set-server = utf8
skip-name-resolve
long_query_time = 1
slow-query-log-file = /home/mysql_logs/log-slow.log
federated
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[mysqlhotcopy]
interactive-timeout
</pre>
==MySQL 8G服务器==
<pre>
db# mkdir -p /home/mysql_data //创建MySQL数据存储目录
db# mkdir -p /home/mysql_logs //创建MySQL日记目录
db# chown mysql.mysql /home/mysql_data/ -R //创建MySQL数据存储目录
db# chown mysql.mysql /home/mysql_logs/ -R //创建MySQL日记目录
db# chown mysql.mysql /var/lib/mysql/performance_schema/ -R
db# mysql_install_db //MySQL 5.5用的是innodb plugin,权限表不结构发生了变化,要使用innodb引擎,需要先使用mysql-install-db 命令生成权限表.
db# chown mysql.mysql /home/mysql_logs/ -R //重新改一下属主;
/etc/my.cnf==============================================================
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
max_allowed_packet = 8M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
thread_cache_size = 8
#query_cache_size= 16M //如果我们使用了MemCached,这个就可以关闭
thread_concurrency = 8
server-id = 1
log-bin = /home/mysql_logs/mysql-bin
max_binlog_size=100M
#expire_logs_days=5
#sync_binlog=1
binlog_cache_size=8M
binlog_format = mixed
replicate-ignore-db = mysql
default-storage-engine = innodb
innodb_file_per_table
innodb_data_home_dir = /home/mysql_data/
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_log_group_home_dir = /home/mysql_logs/
innodb_buffer_pool_size = 5G
innodb_additional_mem_pool_size = 1280M // innodb_buffer_pool_size的25%即可
innodb_log_file_size = 512M // 这个不可以超过512M
innodb_log_buffer_size = 100M
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
innodb_lock_wait_timeout = 50
character-set-server = utf8
skip-name-resolve
long_query_time = 1
slow-query-log-file = /home/mysql_logs/log-slow.log
federated
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[mysqlhotcopy]
interactive-timeout
</pre>
==MySQL 16G服务器==
<pre>
db# mkdir -p /home/mysql_data //创建MySQL数据存储目录
db# mkdir -p /home/mysql_logs //创建MySQL日记目录
db# chown mysql.mysql /home/mysql_data/ -R //创建MySQL数据存储目录
db# chown mysql.mysql /home/mysql_logs/ -R //创建MySQL日记目录
db# chown mysql.mysql /var/lib/mysql/performance_schema/ -R
db# mysql_install_db //MySQL 5.5用的是innodb plugin,权限表不结构发生了变化,要使用innodb引擎,需要先使用mysql-install-db 命令生成权限表.
db# chown mysql.mysql /home/mysql_logs/ -R //重新改一下属主;
/etc/my.cnf==============================================================
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
max_allowed_packet = 8M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
thread_cache_size = 8
#query_cache_size= 16M //如果我们使用了MemCached,这个就可以关闭
thread_concurrency = 8
server-id = 1
log-bin = /home/mysql_logs/mysql-bin
max_binlog_size=100M
#expire_logs_days=5
#sync_binlog=1
binlog_cache_size=8M
binlog_format = mixed
replicate-ignore-db = mysql
default-storage-engine = innodb
innodb_file_per_table
innodb_data_home_dir = /home/mysql_data/
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_log_group_home_dir = /home/mysql_logs/
innodb_buffer_pool_size = 12G
innodb_additional_mem_pool_size = 3G // innodb_buffer_pool_size的25%即可
innodb_log_file_size = 512M // 这个不可以超过512M
innodb_log_buffer_size = 100M
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
innodb_lock_wait_timeout = 50
character-set-server = utf8
skip-name-resolve
long_query_time = 1
slow-query-log-file = /home/mysql_logs/log-slow.log
federated
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[mysqlhotcopy]
interactive-timeout
</pre>
==MySQL 32G服务器==
<pre>
db# mkdir -p /home/mysql_data //创建MySQL数据存储目录
db# mkdir -p /home/mysql_logs //创建MySQL日记目录
db# chown mysql.mysql /home/mysql_data/ -R //创建MySQL数据存储目录
db# chown mysql.mysql /home/mysql_logs/ -R //创建MySQL日记目录
db# chown mysql.mysql /var/lib/mysql/performance_schema/ -R
db# mysql_install_db //MySQL 5.5用的是innodb plugin,权限表不结构发生了变化,要使用innodb引擎,需要先使用mysql-install-db 命令生成权限表.
db# chown mysql.mysql /home/mysql_logs/ -R //重新改一下属主;
/etc/my.cnf==============================================================
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
max_allowed_packet = 8M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
thread_cache_size = 8
#query_cache_size= 16M //如果我们使用了MemCached,这个就可以关闭
thread_concurrency = 8
server-id = 1
log-bin = /home/mysql_logs/mysql-bin
max_binlog_size=100M
#expire_logs_days=5
#sync_binlog=1
binlog_cache_size=8M
binlog_format = mixed
replicate-ignore-db = mysql
default-storage-engine = innodb
innodb_file_per_table
innodb_data_home_dir = /home/mysql_data/
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_log_group_home_dir = /home/mysql_logs/
innodb_buffer_pool_size = 24G
innodb_additional_mem_pool_size = 6G // innodb_buffer_pool_size的25%即可
innodb_log_file_size = 512M // 这个不可以超过512M
innodb_log_buffer_size = 100M
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
innodb_lock_wait_timeout = 50
character-set-server = utf8
skip-name-resolve
long_query_time = 1
slow-query-log-file = /home/mysql_logs/log-slow.log
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[mysqlhotcopy]
interactive-timeout
</pre>
|
|