MySQL优化简明指南(1)
一、在编译时优化MySQL 如果你从源代码分发安装MySQL,要注意,编译过程对以后的目标程序性能有重要的影响,不同的编译方式可能得到类似的目标文件,但性能可能相差很大,因此,在编译安装MySQL适应仔细根据你的应用类型选择最可能好的编译选项。这种定制的M
一、在编译时优化MySQL
如果你从源代码分发安装MySQL,要注意,编译过程对以后的目标程序性能有重要的影响,不同的编译方式可能得到类似的目标文件,但性能可能相差很大,因此,在编译安装MySQL适应仔细根据你的应用类型选择最可能好的编译选项。这种定制的MySQL可以为你的应用提供最佳性能。
技巧:选用较好的编译器和较好的编译器选项,这样应用可提高性能10-30%。(MySQL文档如是说)
1.1、使用pgcc(Pentium GCC)编译器
该编译器(http://www.goof.com/pcg/)针对运行在奔腾处理器系统上的程序进行优化,用pgcc编译MySQL源代码,总体性能可提高10%。当然如果你的服务器不是用奔腾处理器,就不必用它了,因为它是专为奔腾系统设计的。
1.2、仅使用你想使用的字符集编译MySQL
MySQL目前提供多达24种不同的字符集,为全球用户以他们自己的语言插入或查看表中的数据。却省情况下,MySQL安装所有者这些字符集,热然而,最好的选择是指选择一种你需要的。如,禁止除Latin1字符集以外的所有其它字符集:
%>./configure -with-extra-charsets=none [--other-configuration-options]
1.3、将mysqld编译成静态执行文件
将mysqld编译成静态执行文件而无需共享库也能获得更好的性能。通过在配置时指定下列选项,可静态编译mysqld。
%>./configure -with-mysqld-ldflags=-all-static [--other-configuration-options]
1.4、配置样本
下列配置命令常用于提高性能:
%>CFLAGS="-O6 -mpentiumpro -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O6 -mpentiumpro -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared
二、调整服务器
确保运用正确的编译固然重要,但这只是成功的第一步,配置众多的MySQL变量同样对服务器的正常运行起关键作用。你可以将这些变量的赋值存在一个配置文件中,以确保它们在每次启动MySQL时均起作用,这个配置文件就是my.cnf文件。
MySQL已经提供了几个my.cnf文件的样本,可在/usr/local/mysqld/share/mysql/目录下找到。这些文件分别命名为my-small.cnf、 my-medium.cnf、my-large.cnf和my-huge.cnf,规模说明可在描述配置文件适用的系统类型标题中找到。如果在只有相当少内存的系统上运行MySQL,而且只是偶尔的用一下,那么my-small.cnf会比较理想,因为它命令mysqld只使用最少的资源。类似地,如果你计划构建电子商务超市,而且系统拥有2G内存,那么你可能要用到mysql-huge.cnf文件了。
为了利用这些文件中的一个,你需要复制一个最适合需求的文件,改名为my.cnf。你可以选择使用配置文件三种作用范围的一种:
Global:将my.cnf文件复制到服务器的/etc目录下,这使得配置文件中的变量作用于全局,即对所有服务器上的MySQL数据库服务器有效。
Local:将my.cnf文件复制到[MYSQL-INSTALL-DIR]/var/目录下,使得my.cnf作用于特定的服务器。[MYSQL-INSTALL-DIR]表示MySQL安装目录。
User:你可以再限制作用于特定的用户,将my.cnf复制到用户的根目录下。
究竟如何设置my.cnf中的这些变量呢?更进一步说,你可以设置哪一个变量。虽然所用变量对MySQL服务器相对通用,每一个变量与MySQL的的某些组件有更特定的关系。如变量max_connects归在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]标题下插入变量设置。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
