mysql配置(整理、备份)

本文详细介绍了 MySQL 配置文件的各个部分及其作用,包括客户端配置、根目录与数据目录设置、服务端默认字符集、存储引擎、SQL 模式、连接数限制、缓存优化、日志记录等内容。

配置文件位置:根据mysql服务启动时的加载参数决定(可能为my.ini或my.cnf,也可能不使用配置文件)




#客户端可读取信息


[client]


port=3309


[mysql]


default-character-set=utf8


#根目录/数据目录


[mysqld]


#Path to installation directory. All paths are usuallyresolved relative to this.


basedir="C:/Program Files/MySQL/MySQL Server 5.1/"


#Path to the database root


datadir="C:/ProgramData/MySQL/MySQL Server5.1/Data/"


#服务端默认字符集


# The default character set that will be used when a newschema or table is


# created and no character set is defined


character-set-server=utf8


#默认存储引擎


# The default storage engine that will be used when createnew tables when


default-storage-engine=INNODB


# SQL模式


# Set the SQL mode to strict


sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"


#监听队列所能保持的连接数


# back_log是操作系统在监听队列中所能保持的连接数,
#
队列保存了在MySQL连接管理器线程处理之前的连接.
#
如果你有非常高的连接率并且出现"connection refused"报错,
#
你就应该增加此处的值.
#
检查你的操作系统文档来获取这个变量的最大值.
#
如果将back_log设定到比你操作系统限制更高的值,将会没有效果
back_log = 50


#不在TCP/IP端口上进行监听.
#
如果所有的进程都是在同一台服务器连接到本地的mysqld,
#
这样设置将是增强安全的方法
#
所有mysqld的连接都是通过Unix sockets 或者命名管道进行的.
#
注意在windows下如果没有打开命名管道选项而只是用此项
# (
通过 "enable-named-pipe"选项)将会导致mysql服务没有任何作用!
skip-networking


#连接数相关

# MySQL无论如何都会保留一个用于管理员(SUPER)登陆的连接,用于管理员连接数据库进行维护操作,即使当前连接数已经达到了max_connections。因此MySQL的实际# 最大可连接数为max_connections+1;
# 这个参数实际起作用的最大值(实际最大可连接数)为16384,即该参数最大值不能超过16384,即使超过也以16384为准;
# 增加max_connections参数的值,不会占用太多系统资源。系统资源(CPU、内存)的占用主要取决于查询的密度、效率等;
# 该参数设置过小的最明显特征是出现”Too many connections”错误;

# The maximum amount of concurrent sessions the MySQL serverwill


# allow. One of these connections will be reserved for auser with


# SUPER privileges to allow the administrator to login evenif the


# connection limit has been reached.


#查看当前连接数通过执行show status like'%Max_used_connections%';


#Max_used_connections为历史最大连接数


#理想设置状态为Max_used_connections/max_connections*100%85%


max_connections=160


#每个客户端连接最大的错误允许数量,如果达到了此限制.
#
这个客户端将会被MySQL服务阻止直到执行了"FLUSHHOSTS"或者服务重启
#
非法的密码以及其他在链接时的错误会增加此值.
#
查看 "Aborted_connects"状态来获取全局计数器.
max_connect_errors = 10


#缓存


#查询缓存


# Query cache is used to cache SELECT results and laterreturn them


# without actual executing the same query once again. Havingthe query


# cache enabled may result in significant speedimprovements, if your


# have a lot of identical queries and rarely changingtables. See the


# "Qcache_lowmem_prunes"status variable to check if the current value


# is high enough for your load.


# Note: In case your tables change very often or if yourqueries are


# textually different every time, the query cache may resultin a


# slowdown instead of a performance improvement.


query_cache_size=14M


#查询缓存进入条件大小限制


#只有小于此设定值的结果才会被缓冲
#
此设置用来保护查询缓冲,防止一个极大的结果集将其他所有的查询结果都覆盖.
query_cache_limit = 2M


#保持数据锁定


#如果你的系统支持 memlock()函数,你也许希望打开此选项用以让运行中的mysql在在内存高度紧张的时候,数据在内存中保持锁定并且防止可能被swapping out
#
此选项对于性能有益
memlock


#表缓存,增加文件描述符


# The number of open tables for all threads. Increasing thisvalue


# increases the number of file descriptors that mysqldrequires.


# Therefore you have to make sure to set the amount of openfiles


# allowed to at least 4096 in the variable "open-files-limit" in


# section [mysqld_safe]


table_cache=320


#临时表缓存大小限制


# Maximum size for internal (in-memory) temporary tables. Ifa table


# grows larger than this value, it is automaticallyconverted to disk


# based table This limitation is for a single table. Therecan be many


# of them.


tmp_table_size=18M


#独立的内存表所允许的最大容量.
#
此选项为了防止意外创建一个超大的内存表导致永尽所有的内存资源.
max_heap_table_size = 64M


#排序缓冲被用来处理类似ORDER BY以及GROUP BY队列所引起的排序
#
如果排序后的数据无法放入排序缓冲,
#
一个用来替代的基于磁盘的合并分类会被使用
#
查看 "Sort_merge_passes"状态变量.
#
在排序发生时由每个线程分配
sort_buffer_size = 8M


#此缓冲被使用来优化全联合(full JOINs 不带索引的联合).
#
类似的联合在极大多数情况下有非常糟糕的性能表现,
#
但是将此值设大能够减轻性能影响.
#
通过 "Select_full_join"状态变量查看全联合的数量
#
当全联合发生时,在每个线程中分配
join_buffer_size = 8M


#线程缓存


# How many threads we should keep in a cache for reuse. Whena client


# disconnects, the client's threads are put in the cache ifthere aren't


# more than thread_cache_size threads from before. This greatly reduces


# the amount of thread creations needed if you have a lot ofnew


# connections. (Normally this doesn't give a notableperformance


# improvement if you have a good thread implementation.)


thread_cache_size=8


# binlog缓存大小


#在一个事务中binlog为了记录SQL状态所持有的cache大小
#
如果你经常使用大的,多声明的事务,你可以增加此值来获取更大的性能.
#
所有从事务来的状态都将被缓冲在binlog缓冲中然后在提交后一次性写入到binlog
#
如果事务比此值大,会使用磁盘上的临时文件来替代.
#
此缓冲在每个连接的事务第一次更新状态时被创建
binlog_cache_size = 1M


#服务所能处理的请求包的最大大小以及服务所能处理的最大的请求大小(当与大的BLOB字段一起工作时相当必要)
#
每个连接独立的大小.大小动态增加
max_allowed_packet = 16M


#打开二进制日志功能.
#
在复制(replication)配置中,作为MASTER主服务器必须打开此项
#
如果你需要从你最后的备份中做基于时间点的恢复,你也同样需要二进制日志.


#执行show binary logs可以查看所有二进制日志信息


#如何恢复


# Bin/mysqlbinlog–start-datetime=’2011-07-07 18:00:00’ –stop-datetime=’2011-07-07 20:07:13’data/mysql-bin.0000008 |mysql –u root



log-bin=mysql-bin


 


#慢查询记录


#日志目录


log-slow-query=sql_row.log


#超过5s算作慢查询,记录日志


log_query_time=5


 


 





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值