`
中国爪哇程序员
  • 浏览: 167631 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

第一节 MYSQL 参数配置

阅读更多
由于ORACLE价格昂贵。生产开发中开始转用mysql数据。在开发和学习中碰到了许多问题。在这里做下总结。

一 MYSQL 版本
目前有关4.X ,5.X,6.X
每个版本中又有Standdard,Max,Debug 三个类型
当然又分为windows平台下的和LINUX平台


二 配置文件夹

mysql的数据库的系统配置文件叫做my.ini
新下载的绿色版mysql或者安装后的mysql,在根目录下还有好几个后缀是ini的文件
例:my-huge.ini,my-innodb-heavy-4G.ini,my-large.ini,my-medium.ini,my-small.ini,my-template.ini
mysql启动后只会加载my.ini这个配置文件。用其他文件替换my.ini就会修改mysql启动参数。根据名称也可大体明白各ini文件表达的意思。可根据不同情况选用合适的ini启动文件。


三 配置说明

端口号
port=3306
字符集
default-character-set=gbk
安装MYSQL的根目录
basedir="D:/Program Files/MySQL/MySQL Server 5.0/"
数据库目录
datadir="D:/Program Files/MySQL/MySQL Server 5.0/Data/"
存储引荐,另外一个是mysql特有的,还经常用到的是myisam(不支持事务)
default-storage-engine=INNODB(唯一支持事务的引荐)

sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
最大链接数
max_connections=100


以下是配置参数的优化说明
# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
#
#
# Installation Instructions
# ----------------------------------------------------------------------
#
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (@localstatedir@ for this installation) or to
# ~/.my.cnf to set user-specific options.
#
# On Windows you should keep this file in the installation directory
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option
# "--defaults-file".
#
# To run run the server from the command line, execute this in a
# command line shell, e.g.
# mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# To install the server as a Windows service manually, execute this in a
# command line shell, e.g.
# mysqld --install MySQLXY --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# And then execute this in a command line shell to start the server, e.g.
# net start MySQLXY
#
#
# Guildlines for editing this file
# ----------------------------------------------------------------------
#
# In this file, you can use all long options that the program supports.
# If you want to know the options a program supports, start the program
# with the "--help" option.
#
# More detailed information about the individual options can also be
# found in the manual.
#
#
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]

port=3306

[mysql]

default-character-set=gbk


# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306


#Path to installation directory. All paths are usually resolved relative to this.
basedir="D:/Program Files/MySQL/MySQL Server 5.0/"

#Path to the database root
datadir="D:/Program Files/MySQL/MySQL Server 5.0/Data/"

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=gbk

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=100

# Query cache is used to cache SELECT results and later return them
# without actual executing the same query once again. Having the query
# cache enabled may result in significant speed improvements, if your
# have a lot of identical queries and rarely changing tables. 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 your queries are
# textually different every time, the query cache may result in a
# slowdown instead of a performance improvement.
query_cache_size=15M

# The number of open tables for all threads. Increasing this value
# increases the number of file descriptors that mysqld requires.
# Therefore you have to make sure to set the amount of open files
# allowed to at least 4096 in the variable "open-files-limit" in
# section [mysqld_safe]
table_cache=256
table_cache指定表高速缓存的大小。每当MySQL访问一个表时,如果在表缓冲区中还有空间,该表就被打开并放入其中,这样可以更快地访问表内容。通过检查峰值时间的状态值Open_tables和Opened_tables,可以决定是否需要增加table_cache的值。如果你发现open_tables等于table_cache,并且opened_tables在不断增长,那么你就需要增加table_cache的值了(上述状态值可以使用SHOW STATUS LIKE ‘Open%tables’获得)。注意,不能盲目地把table_cache设置成很大的值。如果设置得太高,可能会造成文件描述符不足,从而造成性能不稳定或者连接失败。


# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
tmp_table_size=18M


# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client's threads are put in the cache if there aren't
# more than thread_cache_size threads from before.  This greatly reduces
# the amount of thread creations needed if you have a lot of new
# connections. (Normally this doesn't give a notable performance
# improvement if you have a good thread implementation.)
thread_cache_size=8

根据调查发现以上服务器线程缓存thread_cache_size没有进行设置,或者设置过小,这个值表示可以重新利用保存在缓存中线程的数量,当断开连接时如果缓存中还有空间,那么客户端的线程将被放到缓存中,如果线程重新被请求,那么请求将从缓存中读取,如果缓存中是空的或者是新的请求,那么这个线程将被重新创建,如果有很多新的线程,增加这个值可以改善系统性能.通过比较 Connections 和 Threads_created 状态的变量,可以看到这个变量的作用。(-->表示要调整的值)   根据物理内存设置规则如下:
     1G  ---> 8
     2G  ---> 16
     3G  ---> 32
    >3G  ---> 64


#*** MyISAM Specific options

# The maximum size of the temporary file MySQL is allowed to use while
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
# If the file-size would be bigger than this, the index will be created
# through the key cache (which is slower).
myisam_max_sort_file_size=100G

# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method.  This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_max_extra_sort_file_size=100G

# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method.  This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_sort_buffer_size=35M

# Size of the Key Buffer, used to cache index blocks for MyISAM tables.
# Do not set it larger than 30% of your available memory, as some memory
# is also required by the OS to cache rows. Even if you're not using
# MyISAM tables, you should still set it to 8-64M as it will also be
# used for internal temporary disk tables.
key_buffer_size=8M

# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=64K
read_rnd_buffer_size=256K

# This buffer is allocated when MySQL needs to rebuild the index in
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE
# into an empty table. It is allocated per thread so be careful with
# large settings.
sort_buffer_size=256K


#*** INNODB Specific options ***


# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb

# Additional memory pool that is used by InnoDB to store metadata
# information.  If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS.  As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
innodb_additional_mem_pool_size=2M

这个参数用来设置 InnoDB 存储的数据目录信息和其它内部数据结构的内存池大小。应用程序里的表越多,你需要在这里分配越多的内存。对于一个相对稳定的应用,这个参数的大小也是相对稳定的,也没有必要预留非常大的值。如果 InnoDB 用光了这个池内的内存, InnoDB 开始从操作系统分配内存,并且往 MySQL 错误日志写警告信息。默认值是 1MB ,当发现错误日志中已经有相关的警告信息时,就应该适当的增加该参数的大小。


# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1

innodb将log buffer中的数据写入日志文件并flush磁盘的时间点,取值分别为0、1、2三个。0,表示当事务提交时,不做日志写入操作,而是每秒钟将log buffer中的数据写入日志文件并flush磁盘一次;1,则在每秒钟或是每次事物的提交都会引起日志文件写入、flush磁盘的操作,确保了事务的ACID;设置为2,每次事务提交引起写入日志文件的动作,但每秒钟完成一次flush磁盘操作。显然,设置为0或2可以减小系统的io压力,特别是0时,速度最快,提高mysql写操作的吞吐量,但mysql或操作系统的崩溃、断电都可能会引起数据的丢失,设置为2时os的崩溃和断电可能会引起数据的丢失。


# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=1M

# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system.  Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=83M

# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=17M

# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=8



???????????????????????????????????????????

# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
???????????????????????????????????????????


附件是windows平台下mysql的安装和配置



分享到:
评论

相关推荐

    mysql主从库配置

    ### MySQL 主从库配置详解 #### 一、MySQL 安装与环境变量设置 在进行 MySQL 主从库配置之前,我们需要确保已经正确安装了 MySQL,并设置了相应的环境变量。以下是具体的步骤: 1. **下载 MySQL 免安装版**: - ...

    国家开放大学 数据库运维 形考一 MySQL数据库服务器配置

    MySQL 服务器的配置方法包括启动和停止 MySQL 服务器、连接到 MySQL 服务器、查看错误日志文件、启用二进制日志、慢查询日志和通用查询日志、关闭二进制日志、慢查询日志和通用查询日志、创建数据库、查看系统状态...

    MySQL高级配置和管理

    MySQL的配置主要通过my.cnf文件进行,包括innodb_buffer_pool_size、max_connections、query_cache_size等参数的调整至关重要。例如,innodb_buffer_pool_size用于缓存InnoDB表的数据和索引,适当增大此值可以提高...

    Mysql读写分离配置说明

    第一招、mysql服务的启动和停止 net stop mysql net start mysql 第二招、登陆mysql 语法如下: mysql -u用户名 -p用户密码 键入命令mysql -uroot -p, 回车后提示你输入密码,输入12345,然后回车即可进入到mysql中...

    mysql新版配置详细教程

    此外,性能优化也是配置中重要的一环,如调整innodb_buffer_pool_size参数以适应内存大小,可以有效提升查询速度。 在学习MySQL的过程中,理解SQL语言基础至关重要,包括SELECT查询、INSERT插入、UPDATE更新和...

    mysql服务性能优化my_cnf配置说明详解16G内存[参考].pdf

    在每个连接第一次需要使用这个缓存的时候,一次性分配设置的内存。Sort Buffer 并不是越大越好,因为是连接级的参数,过大的设置可能会耗尽系统内存资源。 5. 连接缓存(Join Buffer) Join Buffer 是 MySQL ...

    MySQL Cluster 7.3.7+CentOS7集群配置入门 MySQL双管理节点配置入门

    Host=mgm_node1_host # 第一个管理节点的主机名或IP Port=1186 # 管理节点的端口号 [ndb_mgmd] Host=mgm_node2_host # 第二个管理节点的主机名或IP Port=1186 [mysql_server] Host=mysql_node_host # SQL节点的...

    MySQL集群配置.txt

    1. **配置文件**:创建`/var/lib/mysql-cluster/config.ini`文件,定义集群参数,包括但不限于: - `[NDBDDEFAULT]`:指定副本数量为2(对于两台服务器的集群而言)。 - `[MYSQLDDEFAULT]`:基本配置项。 - `[NDB...

    mysql5.7.15安装配置方法图文教程借鉴.pdf

    ### MySQL 5.7.15 的安装与配置方法详解 #### 一、软件下载与准备 1. **官方下载**: - 进入 MySQL 官方网站 (`http://dev.mysql.com/downloads/mysql/`)。 - 登录您的 Oracle 账号(如无账号需先注册)。 - ...

    新版 MySQL DBA 高级视频 基于MySQL 5.7 MySQL 8.0版本.rar

    │ 第一课数据库介绍篇.pdf │ 第七课MySQL数据库设计.pdf │ 第三十一课percona-toolkits 的实战及自动化.pdf │ 第三课MySQL授权认证.pdf │ 第九课MySQL字符集.pdf │ 第二十一课MySQL常见错误-converted.pdf │ ...

    mysql学习全解包括配置案例

    4. **参数配置**:MySQL有很多可调整的系统变量,如`max_heap_table_size`和`tmp_table_size`(临时表大小),通过合理调整这些参数,可以优化查询性能和内存使用。 5. **多实例**:在同一台机器上运行多个MySQL...

    Mysql_多实例安装配置方法一

    对于第二个实例,例如`my2.cnf`,你需要更改`port`、`socket`等参数,确保它们与第一个实例不冲突: ```ini [client] #password= your_password port= 3307 socket= /tmp/mysq13307.sock [mysqld] port= 3307 ...

    mysql安装配置教程.docx

    - 此步骤是获取最新版本MySQL软件的第一步,确保从官方网站下载以获得正版软件。 - **下载MySQL安装包**: - 在首页点击“DOWNLOADS”按钮。 - 选择“MySQL Community (GPL) Downloads”以下载适用于个人或小...

    mysql8.0审计插件Mcafee安装详解

    在生产环境中选择软件的版本非常重要:第一要选择永久支持版本;第二尽量不要使用最新版本,除非老版本无法满足需求。 然后,需要选择 Mcafee 插件的版本。查看 Mcafee 插件的所有版本,找到支持当前 MySQL 版本的...

    mysql-5.6.22-winx64的免安装配置方法.docx

    在这一步,你需要创建一个`my.ini`配置文件,指定MySQL的服务和数据目录。将以下内容写入`my.ini`: ```ini [client] port=3306 default-character-set=utf8 [mysqld] # 设置为 MYSQL 的安装目录 ...

    mysql数据库安装,配置,图解

    MySQL 数据库的安装和配置是每个 IT 从业者或开发者必须掌握的基本技能之一。本文将详细介绍 MySQL 的安装步骤、配置选项以及如何通过命令行操作数据库。 首先,安装 MySQL 通常涉及以下步骤: 1. **下载安装包**...

    MySql安装配置及错误处理.zip

    MySQL的安装和配置是使用这个数据库系统的第一步,对于初学者或者新环境的搭建来说,可能涉及到一些挑战,比如错误处理。下面我们将详细探讨MySQL的安装步骤、配置过程以及常见的错误处理方法。 1. **MySQL的安装**...

    MySQL安装配置.md

    本文旨在为用户提供一个详尽的MySQL安装与配置指南,帮助读者在不同操作系统上(如Windows、Linux、macOS等)轻松搭建MySQL数据库服务器。 #### 二、MySQL安装指南 ##### 2.1 下载MySQL - **官方下载地址**:...

    Zabbix监控MySQL配置攻略

    而`mysql.status[*]`则指向一个外部脚本`chk_mysql.sh`,该脚本位于`/usr/local/zabbix/scripts`目录下,参数`$1`代表传递给脚本的第一个参数。 接下来是脚本`chk_mysql.sh`的内容。这个脚本是一个shell脚本,用...

Global site tag (gtag.js) - Google Analytics