Home Database Mysql Tutorial MySQL配置文件my.cnf中文详解附mysql性能优化方法分享

MySQL配置文件my.cnf中文详解附mysql性能优化方法分享

Jun 07, 2016 pm 06:05 PM
mysql performance optimization

Mysql参数优化对于新手来讲,是比较难懂的东西,其实这个参数优化,是个很复杂的东西,对于不同的网站,及其在线量,访问量,帖子数量,网络情况,以及机器硬件配置都有关系,优化不可能一次性完成,需要不断的观察以及调试,才有可能得到最佳效果。

下面先说我的服务器的硬件以及论坛情况,
CPU: 2颗四核Intel Xeon 2.00GHz
内存: 4GB DDR
硬盘: SCSI 146GB
论坛:在线会员 一般在 5000 人左右 – 最高记录是 13264.
下面,我们根据以上硬件配置结合一份已经做过一次优化的my.cnf进行分析说明:有些参数可能还得根据论坛的变化情况以及程序员的程序进行再调整。
[mysqld]
port = 3306
serverid = 1
socket = /tmp/mysql.sock
skip-locking # 避免MySQL的外部锁定,减少出错几率增强稳定性。

skip-name-resolve





























































===================================================================
存储引擎是什么?MySQL中的数据用各种不同的技术存储在文件(或者内 正确的编译方法固然重要,但它只是提高MySQL服务器性能工作的一部分。MySQL服务器的许多参数会影响服务器的性能表现,而且我们可以把这些参数保存到配置文件,使得每次MySQL服务器启动时这些参数都自动发挥作用。这个配置文件就是my.cnf。
MySQL服务器提供了my.cnf文件的几个示例,它们可以在/usr/local/mysql/share/mysql/目录下找到,名字分别为 my-small.cnf、my-medium.cnf、my-large.cnf以及my-huge.cnf。文件名字中关于规模的说明描述了该配置文件适用的系统类型。例如,如果运行MySQL服务器的系统内存不多,而且MySQL只是偶尔使用,那么使用my-small.cnf配置文件最为理想,这个配置文件告诉mysqld daemon使用最少的系统资源。反之,如果MySQL服务器用于支持一个大规模的在线商场,系统拥有2G的内存,那么使用mysql-huge.cnf 最为合适。
要使用上述示例配置文件,我们应该先复制一个最适合要求的配置文件,并把它命名为my.cnf。这个复制得到的配置文件可以按照如下三种方式使用:
全局:把这个my.cnf文件复制到服务器的/etc目录,此时文件中所定义的参数将全局有效,即对该服务器上运行的所有MySQL数据库服务器都有效。
局部:把这个my.cnf文件复制到[MYSQL-INSTALL-DIR]/var/将使该文件只对指定的服务器有效,其中[MYSQL-INSTALL-DIR]表示安装MySQL的目录。
用户:最后,我们还可以把该文件的作用范围局限到指定的用户,这只需把my.cnf文件复制到用户的根目录即可。
那么,如何设置my.cnf文件中的参数呢?或者进一步说,哪些参数是我们可以设置的呢?所有这些参数都对MySQL服务器有着全局性的影响,但同时每一个参数都和MySQL的特定部分关系较为密切。例如,max_connections参数属于mysqld一类。那么,如何才能得知这一点呢?这只需执行如下命令:

% >/usr/local/mysql/libexec/mysqld –help
该命令将显示出和mysqld有关的各种选项和参数。要寻找这些参数非常方便,因为这些参数都在“Possible variables for option –set-variable (-O) are”这行内容的后面。找到这些参数之后,我们就可以在my.cnf文件中按照如下方式设置所有这些参数:

set-variable = max_connections=100

这行代码的效果是:同时连接MySQL服务器的最大连接数量限制为100。不要忘了在my.cnf文件[mysqld]小节加上一个set-variable指令,具体请参见配置文件中的示例。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to optimize MySQL connection speed? How to optimize MySQL connection speed? Jun 29, 2023 pm 02:10 PM

How to optimize MySQL connection speed? Overview: MySQL is a widely used relational database management system that is commonly used for data storage and management in a variety of applications. During development, optimization of MySQL connection speed is critical to improving application performance. This article will introduce some common methods and techniques for optimizing MySQL connection speed. Table of Contents: Use connection pools to adjust connection parameters and optimize network settings. Use indexing and caching to avoid long idle connections. Configure appropriate hardware resources. Summary: Use connection pools.

Analysis of project experience on MySQL database backup and recovery performance optimization Analysis of project experience on MySQL database backup and recovery performance optimization Nov 02, 2023 am 08:53 AM

In the current Internet era, the importance of data is self-evident. As one of the core components of Internet applications, database backup and recovery work is particularly important. However, as the amount of data continues to increase and business requirements become increasingly complex, traditional database backup and recovery solutions can no longer meet the high availability and high performance requirements of modern applications. Therefore, optimizing the backup and recovery performance of MySQL database has become an urgent problem that needs to be solved. In practice, we have adopted a series of project experiences to effectively improve MySQL data

MySQL performance optimization practical guide: in-depth understanding of B+ tree indexes MySQL performance optimization practical guide: in-depth understanding of B+ tree indexes Jul 25, 2023 pm 08:02 PM

MySQL Performance Optimization Practical Guide: In-depth Understanding of B+ Tree Indexes Introduction: As an open source relational database management system, MySQL is widely used in various fields. However, as the amount of data continues to increase and query requirements become more complex, MySQL's performance problems are becoming more and more prominent. Among them, the design and use of indexes are one of the key factors affecting MySQL performance. This article will introduce the principle of B+ tree index and show how to optimize the performance of MySQL with actual code examples. 1. Principle of B+ tree index B+ tree is a

How to use PHP's PDO class to optimize MySQL performance How to use PHP's PDO class to optimize MySQL performance May 10, 2023 pm 11:51 PM

With the rapid development of the Internet, MySQL database has become the core data storage technology for many websites, applications and even enterprises. However, with the continuous growth of data volume and the sharp increase in concurrent access, MySQL's performance problems have become increasingly prominent. PHP's PDO class is also widely used in the development and operation of MySQL because of its efficient and stable performance. In this article, we will introduce how to use the PDO class to optimize MySQL performance and improve the database's response speed and concurrent access capabilities. 1. Introduction to PDO class

How to improve MySQL performance by using dynamic SQL statements How to improve MySQL performance by using dynamic SQL statements May 11, 2023 am 09:28 AM

In modern applications, the MySQL database is a common choice. However, as data volumes grow and business needs continue to change, MySQL performance may suffer. In order to maintain the high performance of MySQL database, dynamic SQL statements have become an important technical means to improve the performance of MySQL. What is a dynamic SQL statement? A dynamic SQL statement refers to the technology of generating SQL statements by a program in an application. In layman's terms, it means treating SQL statements as strings. For large applications,

MySQL performance optimization: Master the features and advantages of TokuDB engine MySQL performance optimization: Master the features and advantages of TokuDB engine Jul 25, 2023 pm 07:22 PM

MySQL performance optimization: Master the characteristics and advantages of the TokuDB engine Introduction: In large-scale data processing applications, performance optimization of the MySQL database is a crucial task. MySQL provides a variety of engines, each with different features and advantages. This article will introduce the features and advantages of the TokuDB engine and provide some code examples to help readers better understand and apply the TokuDB engine. 1. Characteristics of TokuDB engine TokuDB is a high-performance, high-compression rate storage engine.

How to improve MySQL performance by vertically partitioning tables How to improve MySQL performance by vertically partitioning tables May 10, 2023 pm 09:31 PM

With the rapid development of the Internet, the scale of data continues to expand, and the demand for database storage and query efficiency is also increasing. As the most commonly used open source database, MySQL's performance optimization has always been the focus of developers. This article will introduce an effective MySQL performance optimization technology - vertical partition table, and explain in detail how to implement and apply it. 1. What is a vertical partition table? Vertically partitioned tables refer to dividing a table according to column characteristics and storing different columns on different physical storage devices to improve query efficiency.

Data table size management skills in MySQL Data table size management skills in MySQL Jun 15, 2023 am 09:28 AM

As a lightweight relational database management system, MySQL database is widely used in Internet applications and enterprise-level systems. In enterprise-level applications, as the amount of data increases, the size of data tables also continues to increase. Therefore, effective management of data table sizes is crucial to ensuring the performance and reliability of the database. This article will introduce data table size management techniques in MySQL. 1. Data table division As the amount of data continues to increase, the size of the data table also continues to increase, which will cause database performance to decrease and query operations to slow down.

See all articles